From 80173be75f70dfab10d782629fc0c3a46ce673db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thor=20=E9=9B=B7=E7=A5=9E=20Schaeff?= <5748289+thorwebdev@users.noreply.github.com> Date: Wed, 9 Mar 2022 15:40:19 +0800 Subject: [PATCH] fix: update cookie lifetime. (#34) * fix: update cookie lifetime. * chore: update changelog. --- CHANGELOG.md | 4 ++++ src/nextjs/utils/getUser.ts | 9 +++++---- src/shared/utils/constants.ts | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cef7ec2e..c766203d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # CHANGELOG +## 1.2.2 - 2022-03-09 + +- [#34](https://github.com/supabase-community/supabase-auth-helpers/pull/34): fix: update cookie lifetime default from 8h to 7 days. + ## 1.2.1 - 2022-03-09 - [#33](https://github.com/supabase-community/supabase-auth-helpers/pull/33): fix: merge cookieOptions correctly. diff --git a/src/nextjs/utils/getUser.ts b/src/nextjs/utils/getUser.ts index 1ca78a24..8c7d34c9 100644 --- a/src/nextjs/utils/getUser.ts +++ b/src/nextjs/utils/getUser.ts @@ -4,7 +4,7 @@ import { NextApiResponse } from 'next'; import { User, createClient } from '@supabase/supabase-js'; -import { CookieOptions } from '../types'; +import { CookieOptions, ApiError } from '../types'; import { setCookies } from '../../shared/utils/cookies'; import { COOKIE_OPTIONS } from '../../shared/utils/constants'; import { jwtDecoder } from '../../shared/utils/jwt'; @@ -22,7 +22,7 @@ export default async function getUser( | GetServerSidePropsContext | { req: NextApiRequest; res: NextApiResponse }, options: GetUserOptions = {} -): Promise<{ user: User | null; accessToken: string | null }> { +): Promise<{ user: User | null; accessToken: string | null; error?: string }> { try { if ( !process.env.NEXT_PUBLIC_SUPABASE_URL || @@ -90,7 +90,8 @@ export default async function getUser( return { user: user!, accessToken: access_token }; } } catch (e) { - console.log('Error getting user:', e); - return { user: null, accessToken: null }; + const error = e as ApiError; + console.log('Error getting user:', error); + return { user: null, accessToken: null, error: error.message }; } } diff --git a/src/shared/utils/constants.ts b/src/shared/utils/constants.ts index 70a46495..84df4ce1 100644 --- a/src/shared/utils/constants.ts +++ b/src/shared/utils/constants.ts @@ -1,6 +1,6 @@ export const COOKIE_OPTIONS = { name: 'sb', - lifetime: 60 * 60 * 8, + lifetime: 7 * 24 * 60 * 60, // 7 days domain: '', path: '/', sameSite: 'lax'