final logout related fixes and cookies and session
This commit is contained in:
@@ -54,7 +54,7 @@ export const useAuthStore = create<AuthState>()(
|
||||
isAuthenticated: false,
|
||||
loading: false, // Always start with loading false - will be set true only during login/register
|
||||
|
||||
login: async (email, password, rememberMe = false) => {
|
||||
login: async (email, password, rememberMe = false, forceLogout = false) => {
|
||||
set({ loading: true });
|
||||
try {
|
||||
const API_BASE_URL = import.meta.env.VITE_BACKEND_URL || 'https://api.igny8.com/api';
|
||||
@@ -63,11 +63,23 @@ export const useAuthStore = create<AuthState>()(
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({ email, password, remember_me: rememberMe }),
|
||||
credentials: 'include', // Include cookies
|
||||
body: JSON.stringify({ email, password, remember_me: rememberMe, force_logout: forceLogout }),
|
||||
});
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
// Handle session conflict (409)
|
||||
if (response.status === 409 && data.error === 'session_conflict') {
|
||||
set({ loading: false });
|
||||
throw {
|
||||
type: 'SESSION_CONFLICT',
|
||||
message: data.message,
|
||||
existingUser: data.existing_user,
|
||||
requestedUser: data.requested_user,
|
||||
};
|
||||
}
|
||||
|
||||
if (!response.ok || !data.success) {
|
||||
const message = data.error || data.message || 'Login failed';
|
||||
if (response.status === 402) {
|
||||
|
||||
Reference in New Issue
Block a user