-
-
Notifications
You must be signed in to change notification settings - Fork 240
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature(web): Async validate JWT account and sign out the user if the…
…y no longer exist
- Loading branch information
1 parent
3a8d197
commit f1c956a
Showing
3 changed files
with
39 additions
and
2 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 @@ | ||
"use client"; | ||
|
||
import { api } from "@/lib/trpc"; | ||
import { signOut } from "next-auth/react"; | ||
|
||
/** | ||
* This component is used to address a confusion when the JWT token exists but the user no longer exists in the database. | ||
* So this component synchronusly checks if the user is still valid and if not, signs out the user. | ||
*/ | ||
export default function ValidAccountCheck() { | ||
const { error } = api.users.whoami.useQuery(undefined, { | ||
retry: (_failureCount, error) => { | ||
if (error.data?.code === "UNAUTHORIZED") { | ||
return false; | ||
} | ||
return true; | ||
}, | ||
}); | ||
if (error?.data?.code === "UNAUTHORIZED") { | ||
signOut({ | ||
callbackUrl: "/", | ||
}); | ||
} | ||
|
||
return <></>; | ||
} |
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