Skip to content

Commit a684189

Browse files
committedJan 30, 2025·
add signOut
1 parent 5218f80 commit a684189

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed
 

‎web/src/pages/App/AppBar.jsx

+13-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
import { Menu as MenuIcon } from "@mui/icons-material";
22
import { AppBar as MuiAppBar, Box, Button, Divider, IconButton, Toolbar } from "@mui/material";
33
import { styled } from "@mui/material/styles";
4+
import { signOut } from "firebase/auth";
45
import React from "react";
56
import { ErrorBoundary } from "react-error-boundary";
67
import { useDispatch, useSelector } from "react-redux";
78
import { useNavigate } from "react-router-dom";
89

910
import { firebaseApi } from "../../services/firebaseApi";
1011
import { tcApi } from "../../services/tcApi";
12+
import { setAuthUserIsReady } from "../../slices/auth";
1113
import { setDrawerOpen } from "../../slices/system";
14+
import Firebase from "../../utils/Firebase";
1215
import { drawerWidth } from "../../utils/const";
1316

1417
import { AppFallback } from "./AppFallback";
@@ -46,9 +49,16 @@ export function AppBar() {
4649
const handleLogout = () => {
4750
dispatch(firebaseApi.util.resetApiState()); // reset RTKQ
4851
dispatch(tcApi.util.resetApiState()); // reset RTKQ
49-
navigate("/login", {
50-
state: { message: "Logged out successfully.", from: null, search: null },
51-
});
52+
dispatch(setAuthUserIsReady(false));
53+
signOut(Firebase.getAuth())
54+
.then(() => {
55+
navigate("/login", {
56+
state: { message: "Logged out successfully.", from: null, search: null },
57+
});
58+
})
59+
.catch((error) => {
60+
console.error(error);
61+
});
5262
};
5363

5464
return (

‎web/src/pages/App/AppPage.jsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Box } from "@mui/material";
2-
import { onAuthStateChanged } from "firebase/auth";
2+
import { onAuthStateChanged, signOut } from "firebase/auth";
33
import React, { useEffect } from "react";
44
import { ErrorBoundary } from "react-error-boundary";
55
import { useDispatch, useSelector } from "react-redux";
@@ -25,6 +25,7 @@ export function App() {
2525
useEffect(() => {
2626
onAuthStateChanged(Firebase.getAuth(), (user) => {
2727
if (!user) {
28+
dispatch(setAuthUserIsReady(false));
2829
navigate("/login", {
2930
state: {
3031
from: location.pathname,

‎web/src/pages/Login/LoginPage.jsx

+4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
TextField,
1515
Typography,
1616
} from "@mui/material";
17+
import { signOut } from "firebase/auth";
1718
import React, { useEffect, useState } from "react";
1819
import { useDispatch } from "react-redux";
1920
import { useLocation, useNavigate } from "react-router-dom";
@@ -24,6 +25,7 @@ import {
2425
useSignInWithSamlPopupMutation,
2526
} from "../../services/firebaseApi";
2627
import { useCreateUserMutation, useTryLoginMutation } from "../../services/tcApi";
28+
import { setAuthUserIsReady } from "../../slices/auth";
2729
import Firebase from "../../utils/Firebase";
2830

2931
export function Login() {
@@ -41,7 +43,9 @@ export function Login() {
4143
const [tryLogin] = useTryLoginMutation();
4244

4345
useEffect(() => {
46+
dispatch(setAuthUserIsReady(false));
4447
setMessage(location.state?.message);
48+
signOut(Firebase.getAuth());
4549
}, [dispatch, location]);
4650

4751
const callSignInWithEmailAndPassword = async (email, password) => {

0 commit comments

Comments
 (0)
Please sign in to comment.