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

☄️ Use auth0 #224

Merged
merged 2 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ DRIZZLE_DATABASE_URL="postgresql://postgres:postgres@localhost:5432/postgres"
# Generate this with `openssl rand -base64 32`
NEXTAUTH_SECRET=810bd1ccbf7b1d388d98339ac86d420649bdb789c9ac0c1fad383820341b1773

AUTH0_SECRET=810bd1ccbf7b1d388d98339ac86d420649bdb789c9ac0c1fad383820341b1773
AUTH0_BASE_URL='http://localhost:3000'
AUTH0_ISSUER_BASE_URL='https://YOUR_AUTH0_DOMAIN.auth0.com'
AUTH0_CLIENT_ID='YOUR_AUTH0_CLIENT_ID'
AUTH0_CLIENT_SECRET='YOUR_AUTH0_CLIENT_SECRET'

# Generate from https://github.com/settings/developers
GITHUB_ID=
GITHUB_SECRET=
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ jobs:
env:
PLAYWRIGHT: true
DRIZZLE_DATABASE_URL: postgresql://postgres:postgres@localhost:5432/postgres
AUTH0_SECRET: 810bd1ccbf7b1d388d98339ac86d420649bdb789c9ac0c1fad383820341b1773
AUTH0_BASE_URL: "http://localhost:3000"
AUTH0_ISSUER_BASE_URL: "https://YOUR_AUTH0_DOMAIN.auth0.com"
AUTH0_CLIENT_ID: "YOUR_AUTH0_CLIENT_ID"
AUTH0_CLIENT_SECRET: "YOUR_AUTH0_CLIENT_SECRET"
services:
postgres:
image: postgres
Expand Down
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
"drizzle:push": "drizzle-kit push:pg"
},
"dependencies": {
"@auth/core": "^0.27.0",
"@auth/drizzle-adapter": "^0.7.0",
"@auth0/nextjs-auth0": "^3.5.0",
"@hookform/resolvers": "^3.3.4",
"@lexical/code": "^0.13.1",
"@lexical/link": "^0.13.1",
Expand All @@ -46,7 +45,6 @@
"drizzle-orm": "^0.29.3",
"lexical": "^0.13.1",
"next": "14.1.4",
"next-auth": "5.0.0-beta.11",
"next-axiom": "^1.1.1",
"postgres": "^3.4.3",
"react": "^18",
Expand Down
162 changes: 78 additions & 84 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion src/app/api/auth/[...nextauth]/route.ts

This file was deleted.

7 changes: 7 additions & 0 deletions src/app/api/auth/[auth0]/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { handleAuth, handleLogin } from "@auth0/nextjs-auth0";

export const GET = handleAuth({
login: handleLogin({
returnTo: "/api/loginCallback",
}),
});
18 changes: 18 additions & 0 deletions src/app/api/loginCallback/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { NextResponse } from "next/server";
import { UnauthenticatedError } from "@/constants/errors";
import { insertUser } from "@/drizzle/queries/user";

import { getUserId } from "@/lib/auth";

export async function GET(_: Request, context: { params: unknown }) {
const userId = await getUserId();
if (!userId) {
throw new UnauthenticatedError();
}

await insertUser({
id: userId,
});

return NextResponse.redirect(process.env.AUTH0_BASE_URL!);
}
Loading
Loading