Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 1 addition & 39 deletions frontend/src/components/AuthContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,42 +52,4 @@ export function AuthProvider({ children }: { children: ReactNode }) {
useEffect(() => {
let cancelled = false
checkAuthSession().then((authenticated) => {
if (!cancelled) {
setIsAuthenticated(authenticated)
setLoading(false)
}
})
return () => {
cancelled = true
}
}, [])

// A 401 anywhere invalidates the session.
useEffect(() => {
function onAuthRequired() {
setIsAuthenticated(false)
}
window.addEventListener(AUTH_REQUIRED_EVENT, onAuthRequired)
return () => window.removeEventListener(AUTH_REQUIRED_EVENT, onAuthRequired)
}, [])

const markAuthenticated = useCallback(() => {
setIsAuthenticated(true)
}, [])

const signOut = useCallback(async () => {
await logoutSession()
setIsAuthenticated(false)
}, [])

const value = useMemo<AuthContextValue>(
() => ({ isAuthenticated, loading, markAuthenticated, signOut }),
[isAuthenticated, loading, markAuthenticated, signOut],
)

return <AuthContext.Provider value={value}>{children}</AuthContext.Provider>
}

export function useAuth(): AuthContextValue {
return useContext(AuthContext)
}
.catch(err => console.error(err))
Loading
Loading