I would like to use {auth} from "@/auth.ts" as a middleware in my Next/authjs/Prisma/mongodb project
Unanswered
Dwarf Crocodile posted this in #help-forum
Dwarf CrocodileOP
I have setup everything as described on Authjs.dev and everything works fine except when I want to customize my auth() middleware to make it redirect when a user already connected wants to go on my login page per example.
But when I setup the middleware and try to use any Provider authentification, it sends me this as an error:
[auth][error] SessionTokenError: Read more at https://errors.authjs.dev#sessiontokenerror
[auth][cause]: Error: PrismaClient is not configured to run
in Vercel Edge Functions or Edge Middleware. In order to run Prisma Client on edge runtime, either:
- Use Prisma Accelerate: https://pris.ly/d/accelerate
- Use Driver Adapters: https://pris.ly/d/driver-adapters
I use Prisma/MongoDB adapter and I don't want to use Prisma Accelerate :/
The thing I did is to redirect the user with {redirect} from "next/navigation" like this :
import React from "react";
import LoginForm from "./login-form";
import { redirect } from "next/navigation";
export default async function Page() {
const session = await auth();
if (!session) {
return (
#Unknown Channel
<LoginForm />
</>
);
} else {
redirect("/");
}
}
But it doesn't act as a middleware, we can see the login page still 1 sec after the success login...
How can I make my own middleware in my situation please if anyone has spent through this?
Thank you, regards
But when I setup the middleware and try to use any Provider authentification, it sends me this as an error:
[auth][error] SessionTokenError: Read more at https://errors.authjs.dev#sessiontokenerror
[auth][cause]: Error: PrismaClient is not configured to run
in Vercel Edge Functions or Edge Middleware. In order to run Prisma Client on edge runtime, either:
- Use Prisma Accelerate: https://pris.ly/d/accelerate
- Use Driver Adapters: https://pris.ly/d/driver-adapters
I use Prisma/MongoDB adapter and I don't want to use Prisma Accelerate :/
The thing I did is to redirect the user with {redirect} from "next/navigation" like this :
import React from "react";
import LoginForm from "./login-form";
import { redirect } from "next/navigation";
export default async function Page() {
const session = await auth();
if (!session) {
return (
#Unknown Channel
<LoginForm />
</>
);
} else {
redirect("/");
}
}
But it doesn't act as a middleware, we can see the login page still 1 sec after the success login...
How can I make my own middleware in my situation please if anyone has spent through this?
Thank you, regards