Send JWT token with verify email/phone endpoints
All checks were successful
Build frontend / build (push) Successful in 39s

- authFetch now accepts optional token parameter
- verifyEmail/verifyPhone read token from localStorage and send as Bearer header
This commit is contained in:
Claw AI
2026-03-28 16:17:14 +00:00
parent c14c28141f
commit 5a4b018c07

View File

@ -44,14 +44,20 @@ async function apiFetch(endpoint, options = {}) {
}
/**
* Auth fetch — no token attached, returns full { status, data, ok } for status-code handling
* Auth fetch — returns full { status, data, ok } for status-code handling
*/
async function authFetch(endpoint, body) {
async function authFetch(endpoint, body, token = null) {
console.log('[Auth] Request:', `${API_BASE}${endpoint}`);
const headers = { 'Content-Type': 'application/json' };
if (token) {
headers['Authorization'] = `Bearer ${token}`;
console.log('[Auth] Sending with Bearer token');
}
const res = await fetch(`${API_BASE}${endpoint}`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
headers,
body: JSON.stringify(body),
});
@ -262,12 +268,14 @@ export async function sendPhoneOTP() {
export async function verifyEmail(code) {
console.log('[Auth] Verifying email with code:', code);
return authFetch(`/Auth/VerifyEmail?code=${encodeURIComponent(code)}`, {});
const token = typeof window !== 'undefined' ? localStorage.getItem('token') : null;
return authFetch(`/Auth/VerifyEmail?code=${encodeURIComponent(code)}`, {}, token);
}
export async function verifyPhone(code) {
console.log('[Auth] Verifying phone with code:', code);
return authFetch(`/Auth/VerifyPhoneNumber?code=${encodeURIComponent(code)}`, {});
const token = typeof window !== 'undefined' ? localStorage.getItem('token') : null;
return authFetch(`/Auth/VerifyPhoneNumber?code=${encodeURIComponent(code)}`, {}, token);
}
// ─── Helpers ───