Skip to content

Commit

Permalink
fix: wrong redirect url for oidc requests #1909 (#2149)
Browse files Browse the repository at this point in the history
* fix: wrong redirect url for oidc requests #1909

* fix: login not working with https
  • Loading branch information
Meierschlumpf authored Oct 16, 2024
1 parent d4765c1 commit 6469aa2
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 12 deletions.
3 changes: 1 addition & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ DATABASE_URL="file:./database/db.sqlite"
# You can generate a new secret on the command line with:
# openssl rand -base64 32
# https://next-auth.js.org/configuration/options#secret
NEXTAUTH_URL="http://localhost:3000"

AUTH_TRUST_HOST="true"
NEXTAUTH_SECRET="anything"

# Disable analytics
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ EXPOSE $PORT
ENV PORT=${PORT}

ENV DATABASE_URL "file:/data/db.sqlite"
ENV NEXTAUTH_URL "http://localhost:7575"
ENV AUTH_TRUST_HOST="true"
ENV PORT 7575
ENV NEXTAUTH_SECRET NOT_IN_USE_BECAUSE_JWTS_ARE_UNUSED

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"dev": "next dev",
"build": "NEXTAUTH_SECRET=WILL_BE_OVERWRITTEN next build",
"analyze": "ANALYZE=true next build",
"turbo": "DATABASE_URL=file:WILL_BE_OVERWRITTEN.sqlite NEXTAUTH_URL=http://WILL_BE_OVERWRITTEN turbo build",
"turbo": "DATABASE_URL=file:WILL_BE_OVERWRITTEN.sqlite turbo build",
"start": "next start",
"typecheck": "tsc --noEmit",
"export": "next build && next export",
Expand Down
8 changes: 0 additions & 8 deletions src/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,6 @@ const env = createEnv({
DATABASE_URL: z.string().url().default('file:../database/db.sqlite'),
NEXTAUTH_SECRET:
process.env.NODE_ENV === 'production' ? z.string().min(1) : z.string().min(1).optional(),
NEXTAUTH_URL: z.preprocess(
// This makes Vercel deployments not fail if you don't set NEXTAUTH_URL
// Since NextAuth.js automatically uses the VERCEL_URL if present.
(str) => process.env.VERCEL_URL ?? str,
// VERCEL_URL doesn't include `https` so it cant be validated as a URL
process.env.VERCEL ? z.string().min(1) : z.string().url()
),
DOCKER_HOST: z.string().optional(),
DOCKER_PORT: portSchema,
DEMO_MODE: z.string().optional(),
Expand Down Expand Up @@ -136,7 +129,6 @@ const env = createEnv({
runtimeEnv: {
DATABASE_URL: process.env.DATABASE_URL,
NEXTAUTH_SECRET: process.env.NEXTAUTH_SECRET,
NEXTAUTH_URL: process.env.NEXTAUTH_URL,
NEXT_PUBLIC_DISABLE_ANALYTICS: process.env.DISABLE_ANALYTICS,
DOCKER_HOST: process.env.DOCKER_HOST,
DOCKER_PORT: process.env.DOCKER_PORT,
Expand Down
11 changes: 11 additions & 0 deletions src/server/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,17 @@ export const constructAuthOptions = async (
},
adapter: adapter as Adapter,
providers: [...(await getProviders(req.headers)), EmptyNextAuthProvider()],
cookies: {
sessionToken: {
name: 'next-auth.session-token',
options: {
httpOnly: true,
sameSite: 'lax',
path: '/',
secure: true,
},
},
},
jwt: {
async encode(params) {
if (!isCredentialsRequest(req)) {
Expand Down

0 comments on commit 6469aa2

Please sign in to comment.