From b04b8c702f8c080680b9012586fb480898dd3615 Mon Sep 17 00:00:00 2001 From: Kamran Ahmed Date: Fri, 25 Aug 2023 02:19:02 +0100 Subject: [PATCH] Cookie sharing across sub-domains --- src/components/AuthenticationFlow/EmailLoginForm.tsx | 1 + src/components/AuthenticationFlow/GitHubButton.tsx | 1 + src/components/AuthenticationFlow/GoogleButton.tsx | 1 + src/components/AuthenticationFlow/LinkedInButton.tsx | 1 + src/components/AuthenticationFlow/ResetPasswordForm.tsx | 1 + src/components/AuthenticationFlow/TriggerVerifyAccount.tsx | 1 + src/components/Navigation/navigation.ts | 6 ------ 7 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/components/AuthenticationFlow/EmailLoginForm.tsx b/src/components/AuthenticationFlow/EmailLoginForm.tsx index 428ebf04e..6a626b792 100644 --- a/src/components/AuthenticationFlow/EmailLoginForm.tsx +++ b/src/components/AuthenticationFlow/EmailLoginForm.tsx @@ -29,6 +29,7 @@ const EmailLoginForm: FunctionComponent<{}> = () => { Cookies.set(TOKEN_COOKIE_NAME, response.token, { path: '/', expires: 30, + domain: import.meta.env.DEV ? 'localhost' : '.roadmap.sh', }); window.location.reload(); diff --git a/src/components/AuthenticationFlow/GitHubButton.tsx b/src/components/AuthenticationFlow/GitHubButton.tsx index 03b4ffb25..aace17c1f 100644 --- a/src/components/AuthenticationFlow/GitHubButton.tsx +++ b/src/components/AuthenticationFlow/GitHubButton.tsx @@ -62,6 +62,7 @@ export function GitHubButton(props: GitHubButtonProps) { Cookies.set(TOKEN_COOKIE_NAME, response.token, { path: '/', expires: 30, + domain: import.meta.env.DEV ? 'localhost' : '.roadmap.sh', }); window.location.href = redirectUrl; }) diff --git a/src/components/AuthenticationFlow/GoogleButton.tsx b/src/components/AuthenticationFlow/GoogleButton.tsx index 9c91349e7..da45176a1 100644 --- a/src/components/AuthenticationFlow/GoogleButton.tsx +++ b/src/components/AuthenticationFlow/GoogleButton.tsx @@ -60,6 +60,7 @@ export function GoogleButton(props: GoogleButtonProps) { Cookies.set(TOKEN_COOKIE_NAME, response.token, { path: '/', expires: 30, + domain: import.meta.env.DEV ? 'localhost' : '.roadmap.sh', }); window.location.href = redirectUrl; }) diff --git a/src/components/AuthenticationFlow/LinkedInButton.tsx b/src/components/AuthenticationFlow/LinkedInButton.tsx index c92ec7550..152b6a672 100644 --- a/src/components/AuthenticationFlow/LinkedInButton.tsx +++ b/src/components/AuthenticationFlow/LinkedInButton.tsx @@ -60,6 +60,7 @@ export function LinkedInButton(props: LinkedInButtonProps) { Cookies.set(TOKEN_COOKIE_NAME, response.token, { path: '/', expires: 30, + domain: import.meta.env.DEV ? 'localhost' : '.roadmap.sh', }); window.location.href = redirectUrl; }) diff --git a/src/components/AuthenticationFlow/ResetPasswordForm.tsx b/src/components/AuthenticationFlow/ResetPasswordForm.tsx index 21c76dd99..a4f5699ad 100644 --- a/src/components/AuthenticationFlow/ResetPasswordForm.tsx +++ b/src/components/AuthenticationFlow/ResetPasswordForm.tsx @@ -56,6 +56,7 @@ export default function ResetPasswordForm() { Cookies.set(TOKEN_COOKIE_NAME, token, { path: '/', expires: 30, + domain: import.meta.env.DEV ? 'localhost' : '.roadmap.sh', }); window.location.href = '/'; }; diff --git a/src/components/AuthenticationFlow/TriggerVerifyAccount.tsx b/src/components/AuthenticationFlow/TriggerVerifyAccount.tsx index 2b96785cf..e2b926505 100644 --- a/src/components/AuthenticationFlow/TriggerVerifyAccount.tsx +++ b/src/components/AuthenticationFlow/TriggerVerifyAccount.tsx @@ -30,6 +30,7 @@ export function TriggerVerifyAccount() { Cookies.set(TOKEN_COOKIE_NAME, response.token, { path: '/', expires: 30, + domain: import.meta.env.DEV ? 'localhost' : '.roadmap.sh', }); window.location.href = '/'; }) diff --git a/src/components/Navigation/navigation.ts b/src/components/Navigation/navigation.ts index 47f44baa5..65747f384 100644 --- a/src/components/Navigation/navigation.ts +++ b/src/components/Navigation/navigation.ts @@ -4,12 +4,6 @@ import { TOKEN_COOKIE_NAME } from '../../lib/jwt'; export function logout() { Cookies.remove(TOKEN_COOKIE_NAME); - // @FIXME: fix the domain name in the cookie created by the API - Cookies.remove(TOKEN_COOKIE_NAME, { - path: '/', - domain: 'api.roadmap.sh', - }); - // Reloading will automatically redirect the user if required window.location.reload(); }