Next auth authorize does not work on production server

Viewed 73

I have a Symfony based backend server, which handles JWT authentication, database operations etc and Next.js app, which works as a client. On the localhost everything works fine and problem does not appear, but in case we want to call authorize() method from NextAuth it does not work on production server. Both, Symfony and Next App work on the same server, on ports 8088 and 3000. I get 401 Unauthorized error while trying to make a credentials call frontdomain.stage.com/api/auth/callback/credentials? (request data is fine, user should be logged in, in Postman with this body server returns 200).

My .env:

NEXT_PUBLIC_SERVER=https://backdomain.stage.com./

NEXT_PUBLIC_SERVER_SIDE_PROPS=https://backdomain.stage.com/

SENTRY_DSN=somedsn
NEXT_PUBLIC_SENTRY_DSN=somedsn

NEXTAUTH_URL=http://frontdomain.stage.com/

FACEBOOK_ID=someid
FACEBOOK_SECRET=somesecret
NEXTAUTH_SECRET=somesecret

My Credentials provider method from […nextauth].ts:

providers: [
  CredentialsProvider({
    id: "credentials",
    name: "Credentials",
    credentials: {
      email: {
        label: "Email",
        type: "email",
      },
      password: { label: "Password", type: "password" },
    },
    async authorize(credentials, req) {
      try {
        const user = await axios.post(
          process.env.NEXT_PUBLIC_SERVER + "api/login_check",
          {
            username: credentials?.email,
            password: credentials?.password,
          }
        );
        if (user) {
          return { jwt: user.data.token };
        } else {
          return null;
        }
      } catch (e) {
        return null;
      }
    },
  }),

Request from api login check

0 Answers
Related