auth0/nextjs
useUser
挂钩中的用户对象缺少属性
我似乎无法从 auth0/nextjs
中的 useUser 挂钩获取 while 用户对象:
{
"nickname": "example",
"name": "example@yahoo.com",
"picture": "https://s.gravatar.com/avatar/ca48de58bbf91d5963aa…&d=https%3A%2F%2Fcdn.auth0.com%2Favatars%2Fal.png",
"updated_at": "2022-05-19T13:13:29.487Z",
"sub": "auth0|628639882896f400694b6e72"
}
如您所见,缺少许多属性,例如电子邮件等。感谢您提供任何帮助
回答1
你需要修改你的https://auth0.com/docs/get-started/apis/scopes/sample-use-cases-scopes-and-claims。
使用示例,在您的 [...auth0].js
文件中,而不是在 /api/auth/me
中,您将看到所需的信息
import { handleAuth, handleLogin, handleProfile } from '@auth0/nextjs-auth0';
export default handleAuth({
async login(req, res) {
try {
await handleLogin(req, res, {
returnTo: '/api/auth/me',
authorizationParams: {
response_type: 'code',
scope: 'openid profile email',
}
});
} catch (error) {
res.status(error.status || 400).end(error.message);
}
}
});