-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Develop high-level SessionErrorHandler component
- Loading branch information
Showing
3 changed files
with
32 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { notification } from "antd"; | ||
import { signIn, useSession } from "next-auth/react"; | ||
import nProgress from "nprogress"; | ||
import React, { useEffect } from "react"; | ||
|
||
export const SessionErrorHandler: React.FC<{ children: React.ReactNode }> = ({ children }) => { | ||
const { data: session } = useSession(); | ||
|
||
useEffect(() => { | ||
// this error bubbles up from [...nextauth].ts, refreshAccessToken() | ||
if (session?.['error'] === "RefreshAccessTokenError") { | ||
notification['warning']({ | ||
message: 'Login Required', | ||
description: 'Your session has ended. Redirecting to login page...' | ||
}); | ||
nProgress.start(); | ||
signIn('oidc'); // Force sign in to hopefully resolve error | ||
} | ||
}, [session]); | ||
|
||
return ( | ||
<> | ||
{children} | ||
</> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters