Start integrating the onboarding flow with backend 10
This commit is contained in:
@@ -40,7 +40,7 @@ export interface AuthState {
|
||||
canAccess: (resource: string, action: string) => boolean;
|
||||
}
|
||||
|
||||
import { authService } from '../api';
|
||||
import { authService, apiClient } from '../api';
|
||||
|
||||
export const useAuthStore = create<AuthState>()(
|
||||
persist(
|
||||
@@ -61,6 +61,9 @@ export const useAuthStore = create<AuthState>()(
|
||||
const response = await authService.login({ email, password });
|
||||
|
||||
if (response && response.access_token) {
|
||||
// Set the auth token on the API client immediately
|
||||
apiClient.setAuthToken(response.access_token);
|
||||
|
||||
set({
|
||||
user: response.user || null,
|
||||
token: response.access_token,
|
||||
@@ -92,6 +95,9 @@ export const useAuthStore = create<AuthState>()(
|
||||
const response = await authService.register(userData);
|
||||
|
||||
if (response && response.access_token) {
|
||||
// Set the auth token on the API client immediately
|
||||
apiClient.setAuthToken(response.access_token);
|
||||
|
||||
set({
|
||||
user: response.user || null,
|
||||
token: response.access_token,
|
||||
@@ -117,6 +123,10 @@ export const useAuthStore = create<AuthState>()(
|
||||
},
|
||||
|
||||
logout: () => {
|
||||
// Clear the auth token from API client
|
||||
apiClient.setAuthToken(null);
|
||||
apiClient.setTenantId(null);
|
||||
|
||||
set({
|
||||
user: null,
|
||||
token: null,
|
||||
@@ -139,6 +149,9 @@ export const useAuthStore = create<AuthState>()(
|
||||
const response = await authService.refreshToken(refreshToken);
|
||||
|
||||
if (response && response.access_token) {
|
||||
// Set the auth token on the API client immediately
|
||||
apiClient.setAuthToken(response.access_token);
|
||||
|
||||
set({
|
||||
token: response.access_token,
|
||||
refreshToken: response.refresh_token || refreshToken,
|
||||
|
||||
Reference in New Issue
Block a user