summaryrefslogtreecommitdiff
path: root/microservices/04-react-app/src
diff options
context:
space:
mode:
Diffstat (limited to 'microservices/04-react-app/src')
-rw-r--r--microservices/04-react-app/src/contexts/AuthContext.jsx7
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}