From b6d9888e94e737234cff72ecf4e6595739758a68 Mon Sep 17 00:00:00 2001 From: Francisco Marques Date: Tue, 4 Apr 2023 16:53:53 +0100 Subject: [PATCH] feat: refresh token forces refresh instead of checking if token refresh is required (previous behaviour) --- src/pages.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/pages.ts b/src/pages.ts index 165957b..2917f0b 100644 --- a/src/pages.ts +++ b/src/pages.ts @@ -40,11 +40,25 @@ export class PagesRestrictions { return !!accessToken && !!refreshToken } + private refreshToken = async (context: GetServerSidePropsContext) => { + const refreshToken = context.req?.cookies?.[this.refreshTokenKey] + + if (!refreshToken) return false + + try { + await this.handleRefresh(context.res, refreshToken) + } catch (error) { + return false + } + + return true + } + public withSessionRefresh =

( getServerSideProps: GetServerSideProps

= async () => ({ props: {} as P }) ): GetServerSideProps

=> { return async (context) => { - await this.checkSession(context) + await this.refreshToken(context) return await getServerSideProps(context) }