Skip to content

Commit 8971b24

Browse files
committed
set a timeout period of 1 week for access tokens
1 parent 2812573 commit 8971b24

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

pages/api/auth/[...nextauth].js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import NextAuth from 'next-auth'
22
import axios from 'axios'
3+
// TODO(alishaevn): use the api value from https://github.com/assaydepot/rx/issues/21497 in the next phase
4+
import { EXPIRATION_DURATION } from '../../../utils'
35

46
// For more information on each option (and a full list of options) go to: https://next-auth.js.org/configuration/options
57
const authOptions = {
@@ -32,6 +34,7 @@ const authOptions = {
3234
if (account && user) {
3335
return {
3436
accessToken: account.access_token,
37+
accessTokenExpires: Date.now() + EXPIRATION_DURATION,
3538
refreshToken: account.refresh_token,
3639
user,
3740
}
@@ -80,6 +83,7 @@ const refreshAccessToken = async (token) => {
8083
return {
8184
...token,
8285
accessToken: refreshedTokens.access_token,
86+
accessTokenExpires: Date.now() + EXPIRATION_DURATION,
8387
refreshToken: refreshedTokens.refresh_token ?? token.refreshToken, // Fall back to the old refresh token
8488
}
8589
} catch (error) {

utils/constants.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,8 @@ export const NAVIGATION_LINKS = [
103103
// change this to '/services' to have this link to a page for an individual service.
104104
// if you choose to go this route, you can update the content for the service's page at pages/services/[ware].js
105105
export const FEATURED_SERVICE_PATH = '/requests/new'
106+
107+
// TODO(alishaevn): use the api value from https://github.com/assaydepot/rx/issues/21497 in the next phase
108+
// this amount, listed in milliseconds, represents when the access token will expire
109+
// the default is 1 week
110+
export const EXPIRATION_DURATION = 604800000

0 commit comments

Comments
 (0)