Skip to content

Commit

Permalink
feat(web): use id token of auth0 instead of access token in a way to …
Browse files Browse the repository at this point in the history
…have claims
  • Loading branch information
MikaelVallenet committed May 17, 2023
1 parent 9c6e9e0 commit 797957b
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions web/src/components/ProtectedRoute.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,28 @@ import { Dimmer } from "tabler-react";
import { useAuth0 } from "@auth0/auth0-react";
import {setAuthSession} from "../actions/userSession";


//TODO: update redux state with isAuthenticated value
//TODO: dispatch action to update redux state with userSession
//TODO: Then if userSession.isAuthenticated is true & userSession.accesToken is set, render the component
const ProtectedRoute = ({ component: Component, ...rest }) => {
const dispatch = useDispatch();
const userSession = useSelector(state => state.userSession);
const {
isLoading,
isAuthenticated,
loginWithRedirect,
getAccessTokenSilently,
getIdTokenClaims,
} = useAuth0()

if (!isLoading && !isAuthenticated) {
loginWithRedirect()
.then(() => {getAccessTokenSilently()
.then(() => {getIdTokenClaims()
.then((token) => {
console.log(token);
dispatch(setAuthSession(token))
console.log(token.__raw);
dispatch(setAuthSession(token.__raw))
})
})
} else if (!isLoading && isAuthenticated && !userSession.accessToken) {
getAccessTokenSilently().then((token) => {
console.log(token);
dispatch(setAuthSession(token))
getIdTokenClaims().then((token) => {
console.log(token.__raw);
dispatch(setAuthSession(token.__raw))
})
}

Expand Down

0 comments on commit 797957b

Please sign in to comment.