NextAuth v5 not redirecting to provider auth
Unanswered
Short mackerel posted this in #help-forum
Short mackerelOP
Please take a look at the video. It seems like authjs is not redirecting to the authorization url automatically.
signIn server action
"next": "^15.0.1"
"next-auth": "5.0.0-beta.25"
signIn server action
import { signIn as naSignIn, signOut as naSignOut } from "~/server/auth";
import { redirect } from 'next/navigation'
export async function signIn(
provider: string,
credentials?: z.infer<typeof userLoginForm>,
) {
try {
if (provider == "credentials") {
await naSignIn(provider, { ...credentials});
} else await naSignIn(provider);
} catch (error) {
if (isRedirectError(error)) {
return error.message;
} else if (error instanceof CredentialsSignin) {
return error.cause;
} else if (error instanceof ZodError) {
return error.message;
} else if (error instanceof Error) {
console.log(error);
return error.message;
} else if (typeof error === "string") {
return error;
} else {
return "something went wrong";
}
}
if (provider == "credentials") redirect("/", RedirectType.replace)
}
2 Replies
Short mackerelOP
update: so i tried isolating the issue by creating a signin function just for github and it works
export async function signInGitHub() {
await naSignIn("github");
}
but enclosing it in a trycatch block causes issue
export async function signInGitHub() {
try {
await naSignIn("github");
} catch (error) {
console.log(error)
}
}
Error: NEXT_REDIRECT
at async signInGitHub (file://G%3A/repo/soidev/src/actions/auth.ts:41:4)
39 | try {
40 |
> 41 | await naSignIn("github");
| ^
42 | } catch (error) {
43 | console.log(error)
44 | } {
digest: 'NEXT_REDIRECT;push;https://github.com/login/oauth/authorize?scope=read%3Auser+user%3Aemail&response_type=code&client_id=Ov23liiIe84ctEhHHRQZ&redirect_uri=http%3A%2F%2Flocalhost%3A3000%2Fapi%2Fauth%2Fcallback%2Fgithub&code_challenge=I8gdjDtbMZTMhPYySXH0lFStqIEKNKmu2hAkovDtMVE&code_challenge_method=S256;307;'
}