Skip to content
This repository was archived by the owner on Apr 16, 2026. It is now read-only.

Commit 9eaa835

Browse files
committed
+ config import fix
1 parent 13a25c8 commit 9eaa835

2 files changed

Lines changed: 20 additions & 18 deletions

File tree

  • ui-client-side-session-demo/src/contexts
  • ui-server-side-session-demo/src/components/auth

ui-client-side-session-demo/src/contexts/useAuth.js

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,28 @@ import {
66
GoogleAuthProvider,
77
signOut,
88
} from "firebase/auth";
9+
import firebaseApp from "config/firebase-config";
910

1011
export const UserContext = createContext();
1112

1213
const UserProvider = ({ children }) => {
1314
const [state, dispatch] = useReducer(authReducer, initialState);
1415

1516
useEffect(() => {
16-
const unsubscriber = getAuth().onAuthStateChanged(async (user) => {
17-
if (user) {
18-
resetAuth();
19-
} else {
20-
dispatch({
21-
type: RESET_AUTH_STATE,
22-
payload: {
23-
loading: false,
24-
},
25-
});
17+
const unsubscriber = getAuth(firebaseApp).onAuthStateChanged(
18+
async (user) => {
19+
if (user) {
20+
resetAuth();
21+
} else {
22+
dispatch({
23+
type: RESET_AUTH_STATE,
24+
payload: {
25+
loading: false,
26+
},
27+
});
28+
}
2629
}
27-
});
30+
);
2831
return () => unsubscriber();
2932
}, []);
3033

@@ -34,20 +37,21 @@ const UserProvider = ({ children }) => {
3437
Object.keys(claims).filter((claim) => claim.includes("ROLE_"));
3538

3639
// Login
37-
const login = () => signInWithPopup(getAuth(), new GoogleAuthProvider());
40+
const login = () =>
41+
signInWithPopup(getAuth(firebaseApp), new GoogleAuthProvider());
3842

3943
// Logout
40-
const logout = () => signOut(getAuth());
44+
const logout = () => signOut(getAuth(firebaseApp));
4145

4246
const refreshToken = () => {
43-
getAuth()
47+
getAuth(firebaseApp)
4448
.currentUser.getIdToken(true)
4549
.then((idToken) => resetAuth(idToken))
4650
.catch((error) => console.error(error));
4751
};
4852

4953
const resetAuth = () => {
50-
getAuth()
54+
getAuth(firebaseApp)
5155
.currentUser.getIdTokenResult()
5256
.then((idTokenResult) => {
5357
if (typeof idTokenResult.claims != undefined) {

ui-server-side-session-demo/src/components/auth/login.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,7 @@ const LoginModal = ({}) => {
5858
.then((resp) => {
5959
refreshAuthContext();
6060
})
61-
.catch((error) => {
62-
setLoading("Authentication Failed");
63-
})
61+
.catch((error) => setLoading("Authentication Failed"))
6462
}
6563
>
6664
Test Login

0 commit comments

Comments
 (0)