Skip to content

Commit 63f933e

Browse files
committed
feat: integrate Sentry for session expiration tracking and enhance user data handling
1 parent 77ec1c1 commit 63f933e

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

src/providers/AuthProvider.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import * as Sentry from '@sentry/react'
12
import {
23
GithubAuthProvider,
34
GoogleAuthProvider,
@@ -17,6 +18,7 @@ export const AuthProvider = ({ children }: { children: React.ReactNode }) => {
1718
closeAuthModal,
1819
initState,
1920
setAuthError,
21+
user,
2022
openAuthModal,
2123
setConnecting,
2224
logout,
@@ -42,6 +44,7 @@ export const AuthProvider = ({ children }: { children: React.ReactNode }) => {
4244
initState({
4345
user: {
4446
id: user.uid,
47+
connectedAt: new Date(),
4548
name: user.displayName || 'Anonymous',
4649
imageURL: user.photoURL || '',
4750
},
@@ -148,10 +151,18 @@ export const AuthProvider = ({ children }: { children: React.ReactNode }) => {
148151
* and logout the user if the session has expired
149152
*/
150153
useEffect(() => {
151-
const unsubscribe = firebaseAuth.onAuthStateChanged(async (user) => {
152-
if (!user) {
154+
const unsubscribe = firebaseAuth.onAuthStateChanged(async (fbUser) => {
155+
if (!fbUser) {
153156
if (isConnected) {
154157
toast('Session expired, please reconnect', { theme: 'dangerToast' })
158+
159+
Sentry.captureMessage(`Session expired`, {
160+
level: 'info',
161+
extra: {
162+
fbID: user?.id || 'anonymous',
163+
connectedAt: user?.connectedAt?.toISOString(),
164+
},
165+
})
155166
}
156167

157168
await logout()

0 commit comments

Comments
 (0)