disable github auth when localhost environment
Signed-off-by: slumbering <slumbering.pierrot@gmail.com>
This commit is contained in:
parent
a12e08bd76
commit
da08aa54e9
@ -139,46 +139,46 @@ function DocPage(props) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// CUSTOM DOCPAGE
|
// CUSTOM DOCPAGE
|
||||||
const [isUserAuthorized, setIsUserAuthorized] = useState()
|
if (typeof window !== "undefined" && window?.location?.hostname !== "localhost") {
|
||||||
const [isLoading, setIsLoading] = useState(true)
|
const [isUserAuthorized, setIsUserAuthorized] = useState()
|
||||||
const [redirectState, setRedirectState] = useState()
|
const [isLoading, setIsLoading] = useState(true)
|
||||||
const authQuery = qs.parse(location.search);
|
const [redirectState, setRedirectState] = useState()
|
||||||
const [userAccessToken, setUserAccessToken] = useState((() => {
|
const authQuery = qs.parse(location.search);
|
||||||
if (typeof window !== "undefined") return window.localStorage.getItem('user-github-key')
|
const [userAccessToken, setUserAccessToken] = useState((() => {
|
||||||
})())
|
if (typeof window !== "undefined") return window.localStorage.getItem('user-github-key')
|
||||||
|
})())
|
||||||
|
|
||||||
useEffect(async () => {
|
useEffect(async () => {
|
||||||
if (userAccessToken) {
|
if (userAccessToken) {
|
||||||
const user = await getUser(userAccessToken)
|
const user = await getUser(userAccessToken)
|
||||||
setIsUserAuthorized(user)
|
setIsUserAuthorized(user)
|
||||||
} else {
|
} 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);
|
const isUserCollaborator = await checkUserCollaboratorStatus(authQuery.code);
|
||||||
if (isUserCollaborator?.status === 200) {
|
if (isUserCollaborator?.status === 200) {
|
||||||
setUserAccessToken(isUserCollaborator.access_token)
|
setUserAccessToken(isUserCollaborator.access_token)
|
||||||
if (typeof window !== "undefined") window.localStorage.setItem('user-github-key', isUserCollaborator.access_token);
|
if (typeof window !== "undefined") window.localStorage.setItem('user-github-key', isUserCollaborator.access_token);
|
||||||
} else {
|
} else {
|
||||||
setIsUserAuthorized({ status: 401 })
|
setIsUserAuthorized({ status: 401 })
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
setIsLoading(false)
|
||||||
|
}, [userAccessToken])
|
||||||
|
|
||||||
|
|
||||||
|
if (isLoading) return <Spinner />
|
||||||
|
|
||||||
|
if ((isUserAuthorized?.status && isUserAuthorized?.status === 401)) {
|
||||||
|
return <DocPageRedirect />
|
||||||
}
|
}
|
||||||
setIsLoading(false)
|
|
||||||
}, [userAccessToken])
|
|
||||||
|
|
||||||
|
if (!isUserAuthorized) {
|
||||||
if (isLoading) return <Spinner />
|
return (
|
||||||
|
<DocPageAuthentication />
|
||||||
if ((isUserAuthorized?.status && isUserAuthorized?.status === 401)) {
|
)
|
||||||
return <DocPageRedirect />
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isUserAuthorized) {
|
|
||||||
return (
|
|
||||||
<DocPageAuthentication />
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// END CUSTOM DOCPAGE
|
// END CUSTOM DOCPAGE
|
||||||
|
|
||||||
if (!currentDocRoute) {
|
if (!currentDocRoute) {
|
||||||
|
Reference in New Issue
Block a user