-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(logout): add logout feature * chore(home-page): add test logout and organization fetch as test * fix(auth-guard): fix a breakage with empty localstorage
- Loading branch information
Showing
8 changed files
with
85 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { endPoints } from 'src/shared/constants' | ||
import { axiosWithAuth } from 'src/shared/utils/axios' | ||
|
||
export const logoutMutation = async () => { | ||
return axiosWithAuth.post<undefined>(endPoints.auth.jwt.logout) | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,21 @@ | ||
import { Typography } from '@mui/material' | ||
import { Button, Stack, Typography } from '@mui/material' | ||
import { useQuery } from '@tanstack/react-query' | ||
import { useUserProfile } from 'src/core/auth' | ||
import { endPoints } from 'src/shared/constants' | ||
import { axiosWithAuth } from 'src/shared/utils/axios' | ||
|
||
export default function HomePage() { | ||
const { data } = useQuery(['organization'], () => axiosWithAuth.get<Object>(endPoints.organizations.get).then((res) => res.data)) | ||
const { logout } = useUserProfile() | ||
return ( | ||
<Typography variant="h1" color="secondary"> | ||
Setup cloud | ||
</Typography> | ||
<> | ||
<Typography variant="h1" color="secondary" mb={2}> | ||
Setup cloud | ||
</Typography> | ||
<Button onClick={logout} size="large" variant="contained"> | ||
Logout | ||
</Button> | ||
<Stack component={'pre'}>{JSON.stringify(data, null, ' ')}</Stack> | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,11 @@ | ||
export const endPoints = { | ||
auth: { | ||
jwt: { | ||
refresh: '/api/auth/jwt/refresh', | ||
logout: '/api/auth/jwt/logout', | ||
}, | ||
oauthProviders: '/api/auth/oauth-providers', | ||
}, | ||
organizations: { | ||
get: '/api/organizations/', | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { StorageKeys } from 'src/shared/constants' | ||
|
||
export function cookieMatch(name: string, match: string | RegExp | ((value: string) => boolean)): boolean | ||
export function cookieMatch(name: string, match?: undefined | never): string | undefined | ||
export function cookieMatch(name: string, match?: string | RegExp | ((value: string) => boolean)) { | ||
const splittedByName = window.document.cookie?.split(name + '=') | ||
const value = splittedByName?.[1]?.split(';')?.[0] | ||
if (typeof match === 'function') { | ||
return match(value) | ||
} else if (typeof match === 'string') { | ||
return value === match | ||
} else if (match && typeof match === 'object' && match instanceof RegExp) { | ||
return match.test(value) | ||
} else { | ||
return value || undefined | ||
} | ||
} | ||
|
||
export const isAuthenticated = () => cookieMatch(StorageKeys.authenticated, '1') | ||
|
||
export const clearAllCookies = () => { | ||
const cookies = window.document.cookie.split('; ') | ||
for (let cookieIndex = 0; cookieIndex < cookies.length; cookieIndex++) { | ||
const domain = window.location.hostname.split('.') | ||
while (domain.length > 0) { | ||
const cookieBase = | ||
encodeURIComponent(cookies[cookieIndex].split(';')[0].split('=')[0]) + | ||
'=; expires=Thu, 01-Jan-1970 00:00:01 GMT; domain=' + | ||
domain.join('.') + | ||
' ;path=' | ||
const schema = window.location.pathname.split('/') | ||
window.document.cookie = cookieBase + '/' | ||
while (schema.length > 0) { | ||
window.document.cookie = cookieBase + schema.join('/') | ||
schema.pop() | ||
} | ||
domain.shift() | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.