diff options
| author | Kamal Wickramanayake <kamal@inbox.lk> | 2026-07-06 06:32:08 +0530 |
|---|---|---|
| committer | Kamal Wickramanayake <kamal@inbox.lk> | 2026-07-06 06:32:08 +0530 |
| commit | 5ca98df7caebf56990e26aa83a1a2b626ba16660 (patch) | |
| tree | e71cd8298a49c95d7a03697ef4324b342b399f3e /microservices/04-react-app/src | |
| parent | 504045fb23fa75a520a4d2665aea7d423db1fe14 (diff) | |
Diffstat (limited to 'microservices/04-react-app/src')
| -rw-r--r-- | microservices/04-react-app/src/contexts/AuthContext.jsx | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/microservices/04-react-app/src/contexts/AuthContext.jsx b/microservices/04-react-app/src/contexts/AuthContext.jsx index 9bb5937..c02b7a8 100644 --- a/microservices/04-react-app/src/contexts/AuthContext.jsx +++ b/microservices/04-react-app/src/contexts/AuthContext.jsx @@ -9,7 +9,7 @@ export function AuthProvider({ children }) { const [user, setUser] = useState(null); useEffect(() => { - // Fetch user data from your backend API + // Fetch user data from API gateway const fetchUser = async () => { // axios is directly used from Axios library to avoid interceptor // added in services/api.js @@ -32,7 +32,7 @@ export function AuthProvider({ children }) { const login = () => { // Start single sign-on process (Using OAuth2, OpenID) // Access /ui of API gateway. - // API gateway will redirect user to authorization server if the user is not logged in + // API gateway will redirect user to authorization server if the user is not logged in. // If logged in, API gateway will redirect browser to React app itself reloading the app. window.location.href = "/bff/ui"; } @@ -46,6 +46,7 @@ export function AuthProvider({ children }) { withCredentials: true }); // Redirect browser to logout from authorization server. + // This makes sure user is logged out from both the API gateway and OAuth2 authorization server. window.location.href = response.headers.location; // setUser(null) is not needed since browser is redirected. } catch (error) { @@ -81,7 +82,7 @@ export function AuthProvider({ children }) { return false; } - // Provide the state and the modifier function as a value object + // Add the user data and some functions to the AuthContext return ( <AuthContext value={{ user, login, logout, isLoggedIn, isAdmin, isInRole, isInRoles }}> {children} |
