Next.js Discord

Discord Forum

next-auth problem when launching in production thanks docker help please

Unanswered
docokara posted this in #help-forum
Open in Discord
Avatar
docokaraOP
Hi guys, i really need help, i created an app and using nextauth but when i'm launching my projet in production thanks to docker nextauth does not work any more could someone help me i can't figure out what's going on. I can send you dockerfile, docker-compose and .env in dm

that's my docker-compose :
version: "3"

services:
  myapp:
    image: my-app
    container_name: my-app
    ports:
      - 80:3000
    environment:
      NODE_ENV: production
    network_mode: bridge
    restart : always


My dockerfile :
`
FROM node:20.9-alpine3.18

WORKDIR /app

COPY package.json ./

RUN npm install

COPY . .

RUN npm run build

ENV HOSTNAME 0.0.0.0

EXPOSE 3000

ENV PORT 3000

CMD ["npm", "run" ,"start"]


My .env :

NEXTAUTH_URL="https://myip.net"


(Obviously container name and image name are false)

14 Replies

Avatar
DirtyCajunRice | AppDir
that is your only env vars…?
Avatar
docokaraOP
No what else you would like to see ?
Avatar
DirtyCajunRice | AppDir
enough information to actually help. what you have provided isnt enough context.
Avatar
docokaraOP
What should i give additionnaly ?
That's my signin.tsx :
Image
Avatar
docokaraOP
and that's my [...nextauth] :

export const authOptions: NextAuthOptions = {
  providers: [
    CredentialProvider({
      name: 'Credentials',
      credentials: {
        username: { label: 'Username', type: 'text', placeholder: 'username' },
        password: { label: 'Password', type: 'password' },
      },
      async authorize(credentials, req) {
        try {
          if (!credentials) return null

          const { user } = await getUser(credentials.username)

          if (!user) return null

          if (await compare(credentials.password, user.password)) {
            const { error, websites } = await getWebsites(user.username)

            return {
              id: '0',
              username: user.username,
              role: user.role,
              webSites: websites,
              maxWebSites: user.maxWebSites,
            }
          }
          return null
        } catch (error) {
          console.log(error)
          return null
        }
      },
    }),
  ],
  secret: process.env.NEXTAUTH_SECRET,
  session: {
    strategy: 'jwt',
    maxAge: 30 * 24 * 60 * 60, // 30 days
    updateAge: 24 * 60 * 60, // 24 hours
    generateSessionToken: () => {
      return randomUUID?.() ?? randomBytes(32).toString('hex')
    },
  },

  /* eslint-disable-next-line new-cap */
  adapter: MongoDBAdapter(clientPromise, {
    collections: {
      Accounts: MONGO_COLLECTION_ACCOUNTS,
      Sessions: MONGO_COLLECTION_SESSIONS,
      Users: MONGO_COLLECTION_USERS,
      VerificationTokens: MONGO_COLLECTION_VERIFICATION_TOKENS,
    },
    databaseName: MONGO_DATABASE_NAME,
  }),
  pages: {
    signIn: '/auth/signin',
    signOut: '/auth/signout',
  },
not all because i can't send all
It work perfectly in npm run start but not inside container
Avatar
DirtyCajunRice | AppDir
docker isnt a magic bullet
you need to understand how reverse proxying works, networking layers, and headers
Avatar
Asian black bear
Additionally, you haven't shared any error message or explanation what's going wrong.
Avatar
docokaraOP
nothing happens, the credential provider insn't trigger
Yes sorry i'm not use to ask some help
what do you mean ?