-
let { data, status } = useSession({
// required: true,
});
console.log(status) After successfully login the Here is my setup: export default NextAuth({
// Configure one or more authentication providers
providers: [
// ...add more providers here
CredentialsProvider({
id: "credentials",
// The name to display on the sign in form (e.g. "Sign in with...")
name: "Credentials",
type: "credentials",
// The credentials is used to generate a suitable form on the sign in page.
// You can specify whatever fields you are expecting to be submitted.
// e.g. domain, username, password, 2FA token, etc.
// You can pass any HTML attribute to the <input> tag through the object.
credentials: {
email: { label: "email", type: "text", },
password: { label: "Password", type: "password" }
},
async authorize(credentials, req) {
// Add logic here to look up the user from the credentials supplied
const { email, password } = credentials;
let res = await axios.post(`${baseUrl}/auth/login`, {
email,
password
})
let user = res.data?.data;
if (user?.access_token) {
return user
} else {
return null
}
}
})
],
pages: {
signIn: '/login',
signOut: '/sign-up',
error:'/login'
},
callbacks: {
async jwt({ token, user, account, isNewUser }) {
if (user) {
token.accessToken = user.access_token
}
console.log('jwt: token, user, account \n', token,user, account)
return token;
},
// That token store in session
session: async ({ session, user, token, }) => { // this token return above jwt()
session.accessToken = token.accessToken;
return session;
},
},
}) |
Beta Was this translation helpful? Give feedback.
Answered by
tphuc
Apr 27, 2022
Replies: 1 comment 1 reply
-
I found the problem. Was wrapping function MyApp({ Component, pageProps: { session, ...pageProps } }) {
const getLayout = Component.getLayout || ((page) => page)
return getLayout(
<SessionProvider session={session} refetchOnWindowFocus={true}>
<Component {...pageProps} />
</SessionProvider>
)} Solution: function MyApp({ Component, pageProps: { session, ...pageProps } }) {
const getLayout = Component.getLayout || ((page) => page)
return <SessionProvider session={session} refetchOnWindowFocus={true}>
{getLayout(
<Component {...pageProps} />
)}
</SessionProvider>
} |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
tphuc
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I found the problem. Was wrapping
SessionProvider
bygetLayout
:Solution: