Add debug logging to login flow to trace token storage
All checks were successful
Build frontend / build (push) Successful in 41s
All checks were successful
Build frontend / build (push) Successful in 41s
This commit is contained in:
@ -85,13 +85,15 @@ export default function LoginPage() {
|
|||||||
|
|
||||||
const result = await loginFn(formData.credential, formData.password);
|
const result = await loginFn(formData.credential, formData.password);
|
||||||
|
|
||||||
console.log('[Login] Response:', result);
|
console.log('[Login] Response:', JSON.stringify(result));
|
||||||
|
|
||||||
if (result.status === 200) {
|
if (result.status === 200) {
|
||||||
// Login success — store token via AuthService
|
// Login success — store token via AuthService
|
||||||
const token = typeof result.data === 'string' ? result.data : result.data?.token || result.data;
|
console.log('[Login] result.data type:', typeof result.data, 'value:', result.data);
|
||||||
|
const token = typeof result.data === 'string' ? result.data : result.data?.token || result.data?.accessToken || JSON.stringify(result.data);
|
||||||
|
console.log('[Login] Extracted token:', token?.substring?.(0, 50) + '...');
|
||||||
AuthService.addToken(token);
|
AuthService.addToken(token);
|
||||||
console.log('[Login] Token stored via AuthService');
|
console.log('[Login] Token stored, verifying:', AuthService.getToken()?.substring(0, 30));
|
||||||
|
|
||||||
// Decode token to get user info via AuthService
|
// Decode token to get user info via AuthService
|
||||||
const authUser = AuthService.getUser();
|
const authUser = AuthService.getUser();
|
||||||
@ -115,7 +117,13 @@ export default function LoginPage() {
|
|||||||
|
|
||||||
} else if (result.status === 206) {
|
} else if (result.status === 206) {
|
||||||
// Needs OTP verification
|
// Needs OTP verification
|
||||||
console.log('[Login] 206 — OTP required, sending OTP...');
|
console.log('[Login] 206 — result.data:', JSON.stringify(result.data));
|
||||||
|
// Store temp token if returned
|
||||||
|
const tempToken = typeof result.data === 'string' ? result.data : result.data?.token || result.data?.accessToken;
|
||||||
|
if (tempToken) {
|
||||||
|
AuthService.addToken(tempToken);
|
||||||
|
console.log('[Login] Temp token stored for OTP, key:', AuthService.getToken()?.substring(0, 30));
|
||||||
|
}
|
||||||
toast('يرجى إدخال رمز التحقق', {
|
toast('يرجى إدخال رمز التحقق', {
|
||||||
icon: '🔐',
|
icon: '🔐',
|
||||||
style: { background: '#fef3c7', color: '#92400e' },
|
style: { background: '#fef3c7', color: '#92400e' },
|
||||||
@ -166,14 +174,15 @@ export default function LoginPage() {
|
|||||||
console.log('[OTP] Verifying code:', otpCode);
|
console.log('[OTP] Verifying code:', otpCode);
|
||||||
|
|
||||||
const result = await verifyFn(otpCode);
|
const result = await verifyFn(otpCode);
|
||||||
console.log('[OTP] Verify response:', result);
|
console.log('[OTP] Verify response:', JSON.stringify(result));
|
||||||
|
|
||||||
if (result.ok) {
|
if (result.ok) {
|
||||||
// Verified — store token if returned via AuthService
|
// Verified — store final token if returned
|
||||||
const token = typeof result.data === 'string' ? result.data : result.data?.token || result.data;
|
const finalToken = typeof result.data === 'string' ? result.data : result.data?.token || result.data?.accessToken;
|
||||||
if (token && typeof token === 'string' && token.includes('.')) {
|
console.log('[OTP] Final token:', finalToken?.substring?.(0, 50));
|
||||||
AuthService.addToken(token);
|
if (finalToken && typeof finalToken === 'string') {
|
||||||
console.log('[OTP] Token stored via AuthService');
|
AuthService.addToken(finalToken);
|
||||||
|
console.log('[OTP] Final token stored, verifying:', AuthService.getToken()?.substring(0, 30));
|
||||||
}
|
}
|
||||||
|
|
||||||
setIsSuccess(true);
|
setIsSuccess(true);
|
||||||
|
|||||||
Reference in New Issue
Block a user