-
Notifications
You must be signed in to change notification settings - Fork 0
Fix refresh token logic #23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,6 +1,10 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { authService } from "@/features/auth/services/authService"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import type { UserOnboardingRequest } from "@nycu-sdc/core-system-sdk"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { authRefreshToken } from "@nycu-sdc/core-system-sdk"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { useEffect } from "react"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const DEFAULT_AUTH_REFRESH_INTERVAL = 5 * 60 * 1000; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export const useMe = () => | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| useQuery({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -30,3 +34,15 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| isLoading | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export const useAuthRefreshInterval = () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| useEffect(() => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.log("Setting up auth refresh interval"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const interval = setInterval(() => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.log("Refreshing auth token"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| authRefreshToken(""); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, DEFAULT_AUTH_REFRESH_INTERVAL); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+40
to
+42
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return () => clearInterval(interval); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, []); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+39
to
+45
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| useEffect(() => { | |
| console.log("Setting up auth refresh interval"); | |
| const interval = setInterval(() => { | |
| console.log("Refreshing auth token"); | |
| authRefreshToken(""); | |
| }, DEFAULT_AUTH_REFRESH_INTERVAL); | |
| return () => clearInterval(interval); | |
| }, []); | |
| const qc = useQueryClient(); | |
| useEffect(() => { | |
| console.log("Setting up auth refresh interval"); | |
| const interval = setInterval(() => { | |
| console.log("Refreshing auth token"); | |
| authRefreshToken("") | |
| .then(() => { | |
| // Refresh succeeded: ensure user data is up to date. | |
| qc.invalidateQueries({ queryKey: ["user", "me"] }); | |
| }) | |
| .catch(() => { | |
| // Refresh failed (e.g., expired/invalid token): clear cached user. | |
| qc.removeQueries({ queryKey: ["user", "me"] }); | |
| }); | |
| }, DEFAULT_AUTH_REFRESH_INTERVAL); | |
| return () => clearInterval(interval); | |
| }, [qc]); |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These
console.logstatements will run for every mount and every refresh tick, creating noisy logs (and potentially leaking auth-related timing info in production). Please remove them or route through the app’s logging facility behind an environment/debug flag.