Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redirect after login to localhost #2336

Closed
emmarvpol opened this issue Jul 9, 2021 · 1 comment
Closed

Redirect after login to localhost #2336

emmarvpol opened this issue Jul 9, 2021 · 1 comment
Labels
question Ask how to do something or how something works

Comments

@emmarvpol
Copy link

Question 💬

Hello!

I am using Credentials to login on my website. I build my website on localhost and everything worked fine. When i moved to my server, after login, it redirect me to http://localhost:3000/api/auth/callback/credentials instead of http://example.com/api/auth/callback/credentials.

Thanks!

How to reproduce ☕️

import NextAuth from 'next-auth'
import Providers from 'next-auth/providers'

const baseUrl = process.env.BASE_URL

export default NextAuth({
  NEXTAUTH_URL: process.env.BASE_URL,
  providers: [
    Providers.Credentials({
      name: 'your account',
      credentials: {
        email: { label: "Email", type: "text", placeholder: "" },
        password: { label: "Password", type: "password" }
      },

      callbacks: {
        redirect: async (url, baseUrl) => {
          return Promise.resolve(url)
        }
      },

      async authorize(credentials, req) {
        const res = await fetch(`${process.env.BASE_URL}/api/user/login`, {
          method: 'POST',
          body: JSON.stringify(credentials),
          headers: { "Content-Type": "application/json" }
        })

        const user = await res.json()

        if (res.ok && user.response) {
          return user.response
        }

        return null
      }
    })
  ],
  session: {
    jwt: true,
    maxAge: 30 * 24 * 60 * 60
  }

})

Contributing 🙌🏽

Yes, I am willing to help answer this question in a PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Ask how to do something or how something works
Projects
None yet
Development

No branches or pull requests

2 participants