Skip to content

Commit

Permalink
Refactor cookie options
Browse files Browse the repository at this point in the history
  • Loading branch information
Eprince-hub committed Oct 23, 2024
1 parent 3764b64 commit 873a76c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
13 changes: 3 additions & 10 deletions app/api/graphql/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
} from '../../../database/users';
import type { Resolvers } from '../../../graphql/graphqlGeneratedTypes';
import type { Animal } from '../../../migrations/00000-createTableAnimals';
import { secureCookieOptions } from '../../../util/cookies';

export type GraphqlResponseBody =
| {
Expand Down Expand Up @@ -158,11 +159,7 @@ const resolvers: Resolvers = {
(await cookies()).set({
name: 'sessionToken',
value: session.token,
httpOnly: true,
path: '/',
secure: process.env.NODE_ENV === 'production',
maxAge: 60 * 60 * 24, // This is 24 hours
sameSite: 'lax', // For cross site scripting
...secureCookieOptions,
});

return newUser;
Expand Down Expand Up @@ -213,11 +210,7 @@ const resolvers: Resolvers = {
(await cookies()).set({
name: 'sessionToken',
value: session.token,
httpOnly: true,
path: '/',
secure: process.env.NODE_ENV === 'production',
maxAge: 60 * 60 * 24,
sameSite: 'lax',
...secureCookieOptions,
});

return null;
Expand Down
7 changes: 7 additions & 0 deletions util/cookies.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const secureCookieOptions = {
httpOnly: true,
path: '/',
secure: process.env.NODE_ENV === 'production',
maxAge: 60 * 60 * 24, // This is 24 hours
sameSite: 'lax', // For cross site scripting
} as const;

0 comments on commit 873a76c

Please sign in to comment.