@@ -134,5 +134,75 @@ export const getUserById = async (id: string) => {
134134 const exisitingUser = await getUserByEmail(email)
135135
136136```
137+
13713833 . Now, for ` login ` we have to install nextauth v5
138- ` npm i next-auth@beta `
139+ ` npm i next-auth@beta `
140+ 34 . Create ` auth.ts ` file in root directory for configuration
141+ 35 . Add following code to ` auth.ts ` file
142+ - paste the code from website
143+ 36 . Create ` app/api/auth/[...nextauth].ts ` file and paste the code from the wesbite
144+
145+ - remove the edge because prisma does not support it
146+
147+ 37 . Add ` AUTH_SECRET ` in ` .env ` file
148+
149+ - for the development mode we can use any string
150+
151+ 38 . Go to see logs ` http://localhost:3000/api/auth/providers `
152+
153+ 39 . Create middleware in ` middleware.ts ` in root directory
154+
155+ - ` middleware.ts ` file is nextjs specific file
156+ - update matcher to ` matcher: ["/((?!.+\\.[\\w]+$|_next).*)", "/", "/(api|trpc)(.*)"], ` from clerk
157+
158+ 40 . Create ` auth.config.ts ` file in root directory
159+
160+ - paste the code from website
161+
162+ 41 . Update ` auth.ts ` file
163+
164+ ```
165+ // * Comnfiguration for authentication
166+ import NextAuth from "next-auth";
167+ import authConfig from "@/auth.config";
168+ import { db } from "./lib/database.connection";
169+ import { PrismaAdapter } from "@auth/prisma-adapter";
170+ export const {
171+ handlers: { GET, POST },
172+ auth,
173+ } = NextAuth({
174+ adapter: PrismaAdapter(db), // prisma adapter is supported on non edge
175+ session: { strategy: "jwt" },
176+ ...authConfig,
177+ });
178+
179+
180+ ```
181+
182+ 42 . Update ` api/auth/[...nextauth].ts ` file
183+
184+ ```
185+ // * middleware works on the edge
186+
187+ import authConfig from "./auth.config";
188+ import NextAuth from "next-auth";
189+
190+ const { auth } = NextAuth(authConfig);
191+
192+ export default auth((req) => {
193+ // req.auth
194+ });
195+
196+ // Optionally, don't invoke Middleware on some paths
197+ export const config = {
198+ matcher: ["/((?!.+\\.[\\w]+$|_next).*)", "/", "/(api|trpc)(.*)"],
199+ };
200+
201+ ```
202+
203+ 43 . Create ` route.ts ` file in root directory
204+
205+ - this file will contain all types of routes
206+
207+ 44 . Edit middleware.ts file
208+ // cuurently here : 2:32:14
0 commit comments