Skip to content

Session Callback not being called #1332

@skimaharvey

Description

@skimaharvey

After entering the correct credentials I am redirected to the page where I ask for user to be logged in however I am not logged in. I tried looking at the session callback function to see what was returned but after inserting a console.log inside I saw that this function was not called?

Any idea what is wrong with the code below?

Thank you !

const providers = [

    Providers.Credentials({
        name: 'Credentials',
        credentials: {
          username: { label: "Username", type: "text", placeholder: "jsmith" },
          password: {  label: "Password", type: "password" }
        },
        async authorize(credentials) {
          let user;
          if(credentials.username == process.env.USERNAME && credentials.password == process.env.PASSWORD ){
              user = {
                        username: credentials.username,
                        token: credentials.csrfToken
                     }
          }
          if (user) {
            return user
          } else {
            return null
          }
        }
  })
]

const callbacks = {
    async signIn(user, account, profile) {
      return true
    },
    async jwt(token, user) {
      if (user) {
        token.accessToken = user.token
      }
      return token
    },
    async session(session, token) {
      session.accessToken = token.accessToken
      return session
    }
  }
  const options = {
    providers,
    callbacks
  }
export default (req, res) => NextAuth(req, res, options)

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionAsk how to do something or how something works

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions