Send JWT token with verify email/phone endpoints
All checks were successful
Build frontend / build (push) Successful in 39s
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:
@ -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}`);
|
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}`, {
|
const res = await fetch(`${API_BASE}${endpoint}`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers,
|
||||||
body: JSON.stringify(body),
|
body: JSON.stringify(body),
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -262,12 +268,14 @@ export async function sendPhoneOTP() {
|
|||||||
|
|
||||||
export async function verifyEmail(code) {
|
export async function verifyEmail(code) {
|
||||||
console.log('[Auth] Verifying email with code:', 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) {
|
export async function verifyPhone(code) {
|
||||||
console.log('[Auth] Verifying phone with code:', 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 ───
|
// ─── Helpers ───
|
||||||
|
|||||||
Reference in New Issue
Block a user