diff --git a/pages/_app.tsx b/pages/_app.tsx index 640eb28990cc87177bace1a7dc39c6d81271d1ca..c9bf43c9c1f4f09c23470510985082069a12c074 100644 --- a/pages/_app.tsx +++ b/pages/_app.tsx @@ -208,7 +208,7 @@ function MyApp ({ return ( <SessionProvider session={session} - refetchInterval={3 * 60} + refetchInterval={10} refetchOnWindowFocus={true} > <App>{renderComponent()}</App> diff --git a/pages/api/auth/[...nextauth].ts b/pages/api/auth/[...nextauth].ts index 9007c33c144fe12392f972cf76950d26f78f6c4b..8f1f781e6d860c63b9cc392e1adab9b9590ec8aa 100644 --- a/pages/api/auth/[...nextauth].ts +++ b/pages/api/auth/[...nextauth].ts @@ -93,6 +93,7 @@ export const authOptions = { // Initial sign in if (account && user) { return { + lastRefresh: Date.now(), accessToken: account.access_token, accessTokenExpires: account.expires_at, refreshToken: account.refresh_token, @@ -100,8 +101,8 @@ export const authOptions = { } } - // Return previous token if the access token will still not be expired in 60 seconds. - if (Date.now() + 60000 < token.accessTokenExpires) { + if (token.lastRefresh + 10000 > Date.now()) { + // return if last refresh is 10 seconds or younger return token }