docs: 🐛 fix user auth issue + refacto api calls

Signed-off-by: slumbering <slumbering.pierrot@gmail.com>
This commit is contained in:
slumbering
2021-06-14 14:13:31 +02:00
parent f3e5f810f6
commit e8db91fe9b
3 changed files with 48 additions and 38 deletions

View File

@@ -153,14 +153,14 @@ function DocPage(props) {
const user = await getUser(userAccessToken)
setIsUserAuthorized(user)
} else {
if (!isEmpty(authQuery)) { //callback after successful auth with github)
if (!isEmpty(authQuery)) { //callback after successful auth with github
const isUserCollaborator = await checkUserCollaboratorStatus(authQuery.code);
if (isUserCollaborator?.status === 200) {
if (isUserCollaborator?.isAllowed) {
setUserAccessToken(isUserCollaborator.access_token)
if (typeof window !== "undefined") window.localStorage.setItem('user-github-key', isUserCollaborator.access_token);
} else {
setIsUserAuthorized({ status: 401 })
}
setIsUserAuthorized(isUserCollaborator?.isAllowed)
}
}
setIsLoading(false)
@@ -169,11 +169,11 @@ function DocPage(props) {
if (isLoading) return <Spinner />
if ((isUserAuthorized?.status && isUserAuthorized?.status === 401)) {
if (isUserAuthorized === false) {
return <DocPageRedirect />
}
if (!isUserAuthorized) {
if (typeof isUserAuthorized == 'undefined' || isUserAuthorized?.status === 401) {
return (
<DocPageAuthentication />
)