Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/landing #23

Merged
merged 9 commits into from
Jun 14, 2022
Prev Previous commit
Next Next commit
feat(web): enhance cookie storage
  • Loading branch information
tericcabrel committed Jun 13, 2022
commit 4c8922fe86736f8e600247386060b80b546e1fa2
1 change: 1 addition & 0 deletions apps/web/env.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export type EnvironmentVariables = {
APP_ENV: string;
NEXT_PUBLIC_APP_URL: string;
NEXT_PUBLIC_GITHUB_CLIENT_ID: string;
NEXT_PUBLIC_SERVER_URL: string;
};
Expand Down
3 changes: 2 additions & 1 deletion apps/web/src/hooks/authentication/use-auth.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { addDayToDate } from '@sharingan/utils';
import { useCookies } from 'react-cookie';

import { useAuthenticatedUser } from '@/services/users/authenticated-user';
Expand All @@ -9,7 +10,7 @@ const useAuth = () => {
const { data, isLoading } = useAuthenticatedUser();

const saveToken = (token: string) => {
setCookie(COOKIE_NAME, token, { path: '/', secure: true });
setCookie(COOKIE_NAME, token, { expires: addDayToDate(90), path: '/', secure: true });
};

const deleteToken = () => {
Expand Down
4 changes: 2 additions & 2 deletions apps/web/src/utils/apollo.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { ApolloClient, InMemoryCache } from '@apollo/client';
import { useCookies } from 'react-cookie';

import { COOKIE_NAME } from '@/utils/constants';
import { COOKIE_NAME, IS_DEV } from '@/utils/constants';

const useApolloClient = () => {
const [cookies] = useCookies([COOKIE_NAME]);

return new ApolloClient({
cache: new InMemoryCache(),
connectToDevTools: true,
connectToDevTools: IS_DEV,
credentials: 'include',
headers: {
Authorization: cookies[COOKIE_NAME],
Expand Down
2 changes: 2 additions & 0 deletions apps/web/src/utils/constants.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
export const COOKIE_NAME = 'shguid';
export const REGEX_EMAIL = /^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
export const IS_DEV = process.env.APP_ENV === 'development';
export const IS_PROD = process.env.APP_ENV === 'production';