Skip to content
This repository was archived by the owner on Nov 27, 2024. It is now read-only.

Commit fb39b15

Browse files
committed
switch next-auth for lucia-auth
1 parent 8cb404b commit fb39b15

File tree

19 files changed

+433
-232
lines changed

19 files changed

+433
-232
lines changed

README.md

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,9 @@ Some features depend on environment variables (indicated in features list with
2222
- ⚙️ [**T3 Env**](https://github.com/t3-oss/t3-env) - Environment variable validation
2323
- 🌐 [**tRPC**](https://trpc.io/) - Create end-to-end type-safe APIs that work in both client and server components
2424
- ⚡💡 [**WebSockets**](https://pusher.com) - Real-time communication (using Pusher, but can be swapped out for alternatives)
25-
- ❗️ using [pusher-http-edge](https://www.npmjs.com/package/pusher-http-edge) to run on edge, use the [nodejs runtime](src/app/api/trpc/[trpc]/route.ts) with a [stable version](https://www.npmjs.com/package/pusher) if desired
2625
- 🔗 integrates with tRPC for end-to-end type-safe events
2726
- 💽💡 [**Drizzle**](https://orm.drizzle.team/) - ORM with maximal type safety
28-
- 🔒💡 [**NextAuth**](https://next-auth.js.org/) - Flexible and secure authentication
29-
- ❗️ using [next-auth@experimental](https://www.npmjs.com/package/next-auth/v/0.0.0-manual.ffd05533) to run on edge. use the [nodejs runtime](src/app/api/auth/[...nextauth]/route.ts) with a [stable version](https://www.npmjs.com/package/next-auth) if desired
27+
- 🔒💡 [**Lucia Auth**](https://lucia-auth.com/) - Authentication, simple and clean
3028
- 🔗💡 integrates with Drizzle to store auth data
3129

3230
### Development
@@ -101,6 +99,21 @@ Some features depend on environment variables (indicated in features list with
10199

102100
- [`.github/workflows/ci.yml`](.github/workflows/ci.yml) - type-checking and linting (hence these errors are ignored in [`next.config.mjs`](next.config.mjs))
103101

102+
### [Lucia Auth](https://lucia-auth.com/)
103+
104+
💡 (requires enabling)
105+
106+
- [`src/app/api/auth`](src/app/api/auth)
107+
- [`src/app/auth`](src/app/auth)
108+
- [`src/components/auth.tsx`](src/components/auth.tsx)
109+
- [`src/db/schemas/auth.ts)`](src/db/schemas/auth.ts) store auth data in database
110+
- [`src/lib/auth.ts`](src/lib/auth.ts)
111+
- [`types/lucia.d.ts`](types/lucia.d.ts)
112+
113+
#### Examples
114+
115+
- [`src/app/examples/profile/page.tsx`](src/app/examples/profile/page.tsx)
116+
104117
### [MDX](https://mdxjs.com/)
105118

106119
- [`mdx-components.tsx`](mdx-components.tsx)
@@ -111,15 +124,6 @@ Some features depend on environment variables (indicated in features list with
111124
- [`public/manifest.json`](public/manifest.json)
112125
- [`next.config.mjs`](next.config.mjs)
113126

114-
### [NextAuth](https://next-auth.js.org/)
115-
116-
💡 (requires enabling)
117-
118-
- [`src/app/api/auth/[...nextauth]/route.ts`](src/app/api/auth/[...nextauth]/route.ts)
119-
- [`src/components/auth.tsx`](src/components/auth.tsx)
120-
- [`src/db/schemas/auth.ts`](src/db/schemas/auth.ts) — store auth data (users, accounts, sessions, verification tokens) in database
121-
- [`src/lib/auth.ts`](src/lib/auth.ts)
122-
123127
### [Playwright](https://playwright.dev/)
124128

125129
- [`e2e/`](e2e/)

package.json

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
"db:view": "drizzle-kit studio"
2626
},
2727
"dependencies": {
28-
"@auth/core": "0.0.0-manual.59d8da33",
29-
"@auth/drizzle-adapter": "^0.2.1",
3028
"@hookform/resolvers": "^3.3.0",
29+
"@lucia-auth/adapter-mysql": "^2.1.0",
30+
"@lucia-auth/oauth": "^3.5.0",
3131
"@mdx-js/loader": "^2.3.0",
3232
"@mdx-js/react": "^2.3.0",
3333
"@next/mdx": "^13.4.19",
@@ -46,9 +46,9 @@
4646
"client-only": "^0.0.1",
4747
"clsx": "^2.0.0",
4848
"drizzle-orm": "^0.28.2",
49+
"lucia": "^2.7.4",
4950
"lucide-react": "^0.261.0",
5051
"next": "14.0.3",
51-
"next-auth": "0.0.0-manual.ffd05533",
5252
"next-themes": "^0.2.1",
5353
"pusher-http-edge": "^0.4.0",
5454
"pusher-js": "^8.3.0",
@@ -88,10 +88,5 @@
8888
"typescript": "^5",
8989
"vitest": "^0.34.2",
9090
"vitest-dom": "^0.1.0"
91-
},
92-
"pnpm": {
93-
"overrides": {
94-
"@auth/core": "0.12.0"
95-
}
9691
}
9792
}

pnpm-lock.yaml

Lines changed: 37 additions & 85 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/app/api/auth/[...nextauth]/route.ts

Lines changed: 0 additions & 4 deletions
This file was deleted.

src/app/api/auth/logout/route.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import * as context from 'next/headers';
2+
import type { NextRequest } from 'next/server';
3+
import { auth, authRedirects } from '~/lib/auth';
4+
5+
export const POST = async (request: NextRequest) => {
6+
const authRequest = auth.handleRequest(request.method, context);
7+
8+
// Check if user is authenticated
9+
const session = await authRequest.validate();
10+
if (!session) {
11+
return new Response(null, { status: 401 });
12+
}
13+
14+
// Invalidate the current session
15+
await auth.invalidateSession(session.sessionId);
16+
17+
// Delete session cookie
18+
authRequest.setSession(null);
19+
return new Response(null, {
20+
status: 302,
21+
headers: { Location: authRedirects.afterLogout },
22+
});
23+
};

0 commit comments

Comments
 (0)