-
My code: import { githubAuth } from "@/scripts/auth";
import { cookies } from "next/headers";
import { type NextRequest, NextResponse } from "next/server";
export const GET = async (req: NextRequest) => {
if (!req.url) return new NextResponse(null, { status: 400 });
// get url to redirect the user to, with the state
const [url, state] = await githubAuth.getAuthorizationUrl();
// the state can be stored in cookies or localstorage for request validation on callback
cookies().set("oauth_state", state, {
path: "/",
maxAge: 60 * 60,
httpOnly: true,
secure: process.env.NODE_ENV === "production"
});
// redirect to authorization url
return NextResponse.redirect(url.toString(), {});
}; I'm just following the guide and error code 500 appears, there's not even an error message. Also, every call to
|
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 15 replies
-
Hm, this works for me: const [url, state] = await githubAuth.getAuthorizationUrl();
cookies().set("oauth_state", state, {
path: "/",
maxAge: 60 * 60,
httpOnly: true
});
return NextResponse.redirect(url.toString()); Also, the |
Beta Was this translation helpful? Give feedback.
-
This is my UserAttributes type, maybe it has something to do with error. type UserAttributes = Omit<
Omit<import("@prisma/client").AuthUser, "id">,
"role"
> & {
role?: import("@prisma/client").Role;
}; The docs for lucia say that if a column has a default value, you can make the column optional. |
Beta Was this translation helpful? Give feedback.
-
I just remembered I changed the names of some columns. But I used |
Beta Was this translation helpful? Give feedback.
-
Now the error is empty again, but it still gives code 500 |
Beta Was this translation helpful? Give feedback.
-
The problem was with the redirect url, because behaviours where the documentation is only easy to find after the error ocurrs are my favorite. I fixed it by doing this instead of the previous redirect return NextResponse.redirect(new URL("/", req.nextUrl.hostname), {
status: 302
}); |
Beta Was this translation helpful? Give feedback.
The problem was with the redirect url, because behaviours where the documentation is only easy to find after the error ocurrs are my favorite.
I fixed it by doing this instead of the previous redirect