Skip to content

Commit

Permalink
disable github auth when localhost environment
Browse files Browse the repository at this point in the history
Signed-off-by: slumbering <slumbering.pierrot@gmail.com>
  • Loading branch information
slumbering committed Jun 11, 2021
1 parent a12e08b commit da08aa5
Showing 1 changed file with 33 additions and 33 deletions.
66 changes: 33 additions & 33 deletions website/src/theme/DocPage/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,46 +139,46 @@ function DocPage(props) {
);

// CUSTOM DOCPAGE
const [isUserAuthorized, setIsUserAuthorized] = useState()
const [isLoading, setIsLoading] = useState(true)
const [redirectState, setRedirectState] = useState()
const authQuery = qs.parse(location.search);
const [userAccessToken, setUserAccessToken] = useState((() => {
if (typeof window !== "undefined") return window.localStorage.getItem('user-github-key')
})())

useEffect(async () => {
if (userAccessToken) {
const user = await getUser(userAccessToken)
setIsUserAuthorized(user)
} else {
if (!isEmpty(authQuery)) { //callback after successful auth with github)
const isUserCollaborator = await checkUserCollaboratorStatus(authQuery.code);
if (isUserCollaborator?.status === 200) {
setUserAccessToken(isUserCollaborator.access_token)
if (typeof window !== "undefined") window.localStorage.setItem('user-github-key', isUserCollaborator.access_token);
} else {
setIsUserAuthorized({ status: 401 })
if (typeof window !== "undefined" && window?.location?.hostname !== "localhost") {
const [isUserAuthorized, setIsUserAuthorized] = useState()
const [isLoading, setIsLoading] = useState(true)
const [redirectState, setRedirectState] = useState()
const authQuery = qs.parse(location.search);
const [userAccessToken, setUserAccessToken] = useState((() => {
if (typeof window !== "undefined") return window.localStorage.getItem('user-github-key')
})())

useEffect(async () => {
if (userAccessToken) {
const user = await getUser(userAccessToken)
setIsUserAuthorized(user)
} else {
if (!isEmpty(authQuery)) { //callback after successful auth with github)
const isUserCollaborator = await checkUserCollaboratorStatus(authQuery.code);
if (isUserCollaborator?.status === 200) {
setUserAccessToken(isUserCollaborator.access_token)
if (typeof window !== "undefined") window.localStorage.setItem('user-github-key', isUserCollaborator.access_token);
} else {
setIsUserAuthorized({ status: 401 })
}
}
}
}
setIsLoading(false)
}, [userAccessToken])
setIsLoading(false)
}, [userAccessToken])


if (isLoading) return <Spinner />
if (isLoading) return <Spinner />

if ((isUserAuthorized?.status && isUserAuthorized?.status === 401)) {
return <DocPageRedirect />
}
if ((isUserAuthorized?.status && isUserAuthorized?.status === 401)) {
return <DocPageRedirect />
}

if (!isUserAuthorized) {
return (
<DocPageAuthentication />
)
if (!isUserAuthorized) {
return (
<DocPageAuthentication />
)
}
}


// END CUSTOM DOCPAGE

if (!currentDocRoute) {
Expand Down

0 comments on commit da08aa5

Please sign in to comment.