[Sample Use Cases: Actions with Authorization]
I am using nextjs with next-auth, and followed this guide above to add user role to token. Also assigned my account to an admin role under User Management/Roles on the auth0 dashboard
import useAuth from "../context/useAuth";
export default function Profile() {
const { session, status, update } = useAuth();
const role = !session?.user["https://<website>/roles"];
if (session) {
return (
<>
<div>Hello {session.user.name}</div>
<div>Role: {role}</div>
</>
);
}
}
useAuth.js
import { useSession, signIn, signOut } from "next-auth/react";
const useAuth = () => {
const { data: session, status, update } = useSession();
return { session, status, update, signIn, signOut };
};
export default useAuth;
I’m able to get the name from session.user.name, but can’t seem to retrieve the role as https:///roles returns an error and the page can’t even load. Is this the correct way to retrieve roles?
Running the test in auth0 actions with a random user returns this which seems to be working
[
{
"name": "https://<website>/roles",
"target": "idToken",
"type": "SetCustomClaim",
"value": []
},
{
"name": "https://<website>/roles",
"target": "accessToken",
"type": "SetCustomClaim",
"value": []
}
]