@@ -1,6 +1,7 @@
|
||||
import React, { createContext, useContext, useState, useEffect } from 'react';
|
||||
import * as msal from '@azure/msal-browser';
|
||||
import { msalConfig, loginRequest } from '../AuthConfig';
|
||||
// ✅ Correction: Import de API_BASE_URL
|
||||
import { msalConfig, loginRequest, API_BASE_URL } from '../authConfig';
|
||||
|
||||
const AuthContext = createContext();
|
||||
|
||||
@@ -19,7 +20,12 @@ export const AuthProvider = ({ children }) => {
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
const [isMsalInitialized, setIsMsalInitialized] = useState(false);
|
||||
|
||||
const getApiUrl = (endpoint) => `http://localhost:3000/${endpoint}`;
|
||||
// ✅ Fonction corrigée pour construire l'URL
|
||||
const getApiUrl = (endpoint) => {
|
||||
const cleanEndpoint = endpoint.startsWith('/') ? endpoint.slice(1) : endpoint;
|
||||
// API_BASE_URL est "/api", donc cela retourne "/api/endpoint"
|
||||
return `${API_BASE_URL}/${cleanEndpoint}`;
|
||||
};
|
||||
|
||||
// --- Vérifie l'autorisation de l'utilisateur via groupes
|
||||
const checkUserAuthorization = async (userPrincipalName, accessToken) => {
|
||||
@@ -167,7 +173,7 @@ export const AuthProvider = ({ children }) => {
|
||||
if (authResult.authorized) {
|
||||
setUser({
|
||||
id: syncResult?.localUserId || entraUser.id,
|
||||
CollaborateurADId: syncResult?.localUserId, // ⭐ AJOUT
|
||||
CollaborateurADId: syncResult?.localUserId,
|
||||
entraUserId: entraUser.id,
|
||||
name: entraUser.displayName,
|
||||
prenom: entraUser.givenName || entraUser.displayName?.split(' ')[0] || '',
|
||||
@@ -179,8 +185,8 @@ export const AuthProvider = ({ children }) => {
|
||||
jobTitle: entraUser.jobTitle,
|
||||
department: entraUser.department,
|
||||
officeLocation: entraUser.officeLocation,
|
||||
typeContrat: syncResult?.typeContrat || '37h', // ⭐ AJOUT
|
||||
dateEntree: syncResult?.dateEntree || null, // ⭐ AJOUT
|
||||
typeContrat: syncResult?.typeContrat || '37h',
|
||||
dateEntree: syncResult?.dateEntree || null,
|
||||
groups: authResult.groups
|
||||
});
|
||||
setIsAuthorized(true);
|
||||
|
||||
Reference in New Issue
Block a user