-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #201 from daithihearn/go-migration
Go migration
- Loading branch information
Showing
71 changed files
with
2,220 additions
and
1,583 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
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,49 @@ | ||
import { useAuth0 } from "@auth0/auth0-react" | ||
import { useEffect, useMemo, useState } from "react" | ||
import jwt_decode from "jwt-decode" | ||
|
||
const AUTH0_AUDIENCE = process.env.REACT_APP_AUTH0_AUDIENCE as string | ||
const AUTH0_SCOPE = process.env.REACT_APP_AUTH0_SCOPE as string | ||
|
||
interface JWTToken { | ||
permissions: string[] | ||
} | ||
|
||
const useAccessToken = () => { | ||
const [accessToken, setAccessToken] = useState<string | undefined>() | ||
const { user, isAuthenticated, getAccessTokenSilently } = useAuth0() | ||
|
||
useEffect(() => { | ||
if (isAuthenticated && user) { | ||
getAccessTokenSilently({ | ||
authorizationParams: { | ||
audience: AUTH0_AUDIENCE, | ||
redirect_uri: window.location.origin, | ||
scope: AUTH0_SCOPE, | ||
}, | ||
}).then(token => { | ||
setAccessToken(token) | ||
}) | ||
} | ||
}, [user, isAuthenticated, getAccessTokenSilently]) | ||
|
||
const isPlayer = useMemo(() => { | ||
if (!accessToken) { | ||
return false | ||
} | ||
const decodedAccessToken = jwt_decode<JWTToken>(accessToken) | ||
return decodedAccessToken.permissions.indexOf("read:game") !== -1 | ||
}, [accessToken]) | ||
|
||
const isAdmin = useMemo(() => { | ||
if (!accessToken) { | ||
return false | ||
} | ||
const decodedAccessToken = jwt_decode<JWTToken>(accessToken) | ||
return decodedAccessToken.permissions.indexOf("write:admin") !== -1 | ||
}, [accessToken]) | ||
|
||
return { isPlayer, isAdmin, accessToken: accessToken } | ||
} | ||
|
||
export default useAccessToken |
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 was deleted.
Oops, something went wrong.
Oops, something went wrong.