User profile is missing from session in v4 #3639
-
Hello, I just upgraded to v4 (specifically 4.1.0) and I'm trying to auth via IdentityServer4 provider but for some reason it's returning the following session:
I've followed the docs and setting it up with Demo IdentityServer4 but no go. Here's my import NextAuth from 'next-auth';
import IdentityServer4Provider from 'next-auth/providers/identity-server4';
import { NEXTAUTH_SECRET } from '@/config/env-vars';
export default NextAuth({
providers: [
IdentityServer4Provider({
id: 'demo-identity-server',
name: 'Demo IdentityServer4',
authorization: {
params: { scope: 'openid profile email api offline_access' }
},
issuer: 'https://demo.identityserver.io/',
clientId: 'interactive.confidential',
clientSecret: 'secret'
})
],
secret: NEXTAUTH_SECRET,
session: {
strategy: 'jwt'
},
}); And my import { useSession, signIn, signOut } from 'next-auth/react';
import * as React from 'react';
type LayoutProps = {
children: React.ReactNode;
};
export function Layout({ children }: LayoutProps) {
const { data: session } = useSession();
return (
<div>
{session ? (
<>
Signed in as {session.user.email} <br />
<button onClick={() => signOut()}>Sign out</button>
</>
) : (
<>
Not signed in <br />
<button onClick={() => signIn()}>Sign in</button>
</>
)}
{children}
</div>
);
} Also some callbacks: // /signin profile object
profile: {
nbf: 1642236483,
exp: 1642236783,
iss: 'https://demo.identityserver.io',
aud: 'interactive.confidential',
iat: 1642236483,
at_hash: 'Ee1sTSMSCGT4Q4UaCjL7jg',
s_hash: 'CVv0sE1AHsO2JgFQFTOHpg',
sid: '57B11D83CC3B16BAD42681C479AA24DE',
sub: '1',
auth_time: 1642236007,
idp: 'local',
amr: [ 'pwd' ]
}
// /signin user object
user: { id: '1', name: undefined, email: undefined, image: null }
// /session token obj
token: {
picture: null,
sub: '1',
iat: 1642236485,
exp: 1644828485,
jti: 'dfb2891b-376a-420e-a869-2e19a8d732c5'
}
// /session session obj
session: {
user: { name: undefined, email: undefined, image: null },
expires: '2022-02-14T08:48:05.772Z'
} Is there some new config option(s) that I must provide that I'm missing or something else? Any help is appreciated! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
I forked the example repo and added my changes to repro here: https://github.com/makezi/next-auth-example. The only changes that was added was to add the IdentityServer4 provider to |
Beta Was this translation helpful? Give feedback.
-
The profile you printed is the same one we receive from the Provider. The demo app doesn't seem to return all the information. You can verify by printing the returned You might need extra scopes, or the Demo simply cannot return that information. I have used the IDS4 provider in production before, so I can assure you if configured correctly, it should work. |
Beta Was this translation helpful? Give feedback.
The profile you printed is the same one we receive from the Provider. The demo app doesn't seem to return all the information. You can verify by printing the returned
id_token
and pasting it into jwt.ioYou might need extra scopes, or the Demo simply cannot return that information. I have used the IDS4 provider in production before, so I can assure you if configured correctly, it should work.