-
-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
262 additions
and
293 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import type { Path } from 'react-router'; | ||
|
||
import type * as H from 'history'; | ||
import { jwtDecode } from 'jwt-decode'; | ||
import type { Me, SignInRequest, SignInResponse } from 'types'; | ||
|
||
import { ACCESS_TOKEN, alovaInstance } from '../../api/endpoints'; | ||
|
||
export const SIGN_IN_PATHNAME = 'loginPathname'; | ||
export const SIGN_IN_SEARCH = 'loginSearch'; | ||
|
||
export const verifyAuthorization = () => | ||
alovaInstance.Get('/rest/verifyAuthorization'); | ||
export const signIn = (request: SignInRequest) => | ||
alovaInstance.Post<SignInResponse>('/rest/signIn', request); | ||
|
||
export function getStorage() { | ||
return localStorage || sessionStorage; | ||
} | ||
|
||
export function storeLoginRedirect(location?: H.Location) { | ||
if (location) { | ||
getStorage().setItem(SIGN_IN_PATHNAME, location.pathname); | ||
getStorage().setItem(SIGN_IN_SEARCH, location.search); | ||
} | ||
} | ||
|
||
export function clearLoginRedirect() { | ||
getStorage().removeItem(SIGN_IN_PATHNAME); | ||
getStorage().removeItem(SIGN_IN_SEARCH); | ||
} | ||
|
||
export function fetchLoginRedirect(): Partial<Path> { | ||
const signInPathname = getStorage().getItem(SIGN_IN_PATHNAME); | ||
const signInSearch = getStorage().getItem(SIGN_IN_SEARCH); | ||
clearLoginRedirect(); | ||
return { | ||
pathname: signInPathname || `/dashboard`, | ||
search: (signInPathname && signInSearch) || undefined | ||
}; | ||
} | ||
|
||
export const clearAccessToken = () => localStorage.removeItem(ACCESS_TOKEN); | ||
export const decodeMeJWT = (accessToken: string): Me => jwtDecode(accessToken); | ||
|
||
export function addAccessTokenParameter(url: string) { | ||
const accessToken = getStorage().getItem(ACCESS_TOKEN); | ||
if (!accessToken) { | ||
return url; | ||
} | ||
const parsedUrl = new URL(url); | ||
parsedUrl.searchParams.set(ACCESS_TOKEN, accessToken); | ||
return parsedUrl.toString(); | ||
} |
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
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
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
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
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
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,4 +1,4 @@ | ||
import type { Blocker } from 'react-router-dom'; | ||
import type { Blocker } from 'react-router'; | ||
|
||
import { | ||
Button, | ||
|
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
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
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
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
Oops, something went wrong.