After running my website on Vercel, I want to transition to a custom server setup on a dedicated server. My code works perfectly without docker.
I am using Next Auth, Drizzle, and Docker. The sign-in button works, then you are redirected to Google where you fill in your info, but it is never able to redirect back to my website–it just hangs forever. I’ve even tried setting up console.log statements in the signIn callback, but nothing is logged. The only thing I get in the console is a 302 response code once I manually close the page, stopping the loading.
Below is a snippet of my package.json, docker-compose.yaml, and auth.js.
package.json
"@auth/drizzle-adapter": "^1.1.0",
"drizzle-kit": "^0.21.2",
"drizzle-orm": "^0.30.10",
"next-auth": "^5.0.0-beta.4",
"next": "^14.2.3"
docker-compose.yaml
services:
app:
image: node:22.2
working_dir: /app
command: sh -c 'npm i && npm run dev'
depends_on:
- db
ports:
- 127.0.0.1:3000:3000
volumes:
- .:/app
environment:
- NODE_ENV=development
- TURBOPACK=1
- CHOKIDAR_USEPOLLING=true
- WATCHPACK_POLLING=true
env_file:
- .env
restart: unless-stopped
db:
image: postgres:16.3
ports:
- 127.0.0.1:5432:5432
volumes:
- ./db:/var/lib/postgresql/data
env_file:
- .env
restart: unless-stopped
auth.js
const scopes = ['userinfo.profile', 'userinfo.email']
.map(scope => `https://www.googleapis.com/auth/${scope}`)
.join(' ')
export const {
handlers: { GET, POST },
auth
} = NextAuth({
adapter: DrizzleAdapter(db, {
usersTable: users,
accountsTable: accounts,
sessionsTable: sessions,
verificationTokensTable: verificationTokens
}) as Adapter,
providers: [
GoogleProvider({
clientId: process.env.GOOGLE_CLIENT_ID!,
clientSecret: process.env.GOOGLE_CLIENT_SECRET!,
authorization: {
params: { scope: scopes }
}
})
],
callbacks: {
signIn: async ({ user }) => {
console.log('signIn', user)
if (!('customerId' in user)) {
// Just created account
console.log('no customer id')
const { id: customerId } = await stripe.customers.create({
metadata: { userId: user.id! },
name: user.name!,
email: user.email!
})
console.log('created customer id', customerId)
;(user as any).customerId = customerId
}
return true
},
session: async ({ session, user }) => {
if (session.user)
Object.assign(
session.user,
pick(
user,
'id',
'phone',
'allowNotifications',
'customerId'
)
)
return session
}
},
cookies: {
sessionToken: {
name: `${!DEV ? '__Secure-' : ''}authjs.session-token`,
options: {
httpOnly: true,
sameSite: 'lax',
path: '/',
domain: !DEV
? new URL(process.env.NEXT_PUBLIC_ORIGIN!).hostname
: undefined,
secure: !DEV
}
}
},
trustHost: true
})
On a side note, after moving to Docker, my google fonts started throwing this error:
Error while requesting resource
There was an issue establishing a connection while requesting https://fonts.googleapis.com/css2?family=Inter:wght@400;700;900&display=swap.
But the auth is a more pressing issue.