Skip to content

Commit

Permalink
fix: update cookie lifetime. (#34)
Browse files Browse the repository at this point in the history
* fix: update cookie lifetime.

* chore: update changelog.
  • Loading branch information
thorwebdev authored Mar 9, 2022
1 parent 2f800f6 commit 80173be
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
9 changes: 5 additions & 4 deletions src/nextjs/utils/getUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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 ||
Expand Down Expand Up @@ -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 };
}
}
2 changes: 1 addition & 1 deletion src/shared/utils/constants.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down

0 comments on commit 80173be

Please sign in to comment.