NextAuth auto sign in after user registiration
Unanswered
Savannah posted this in #help-forum
SavannahOP
Hey everyone,
I'm currently working on an app and using NextAuth.
I've set up the sign-up flow, and users are able to register successfully.
However, after registration, they're not automatically signed in, and they have to manually log in again.
After registiration, I keep getting error below even tough I have added secret. The error only occurs when i try to implement auto sign in feature
Thanks in advance
I'm currently working on an app and using NextAuth.
I've set up the sign-up flow, and users are able to register successfully.
However, after registration, they're not automatically signed in, and they have to manually log in again.
function RegisterForm() {
const [formState, formAction] = useFormState(register, {});
const router = useRouter();
const autoSignIn = async () => {
await signIn("credentials", {
email: formState?.registeredUser.email,
password: formState?.registeredUser.password,
redirect: true,
redirectTo: "/"
});
};
useEffect(() => {
if (formState?.success) autoSignIn();
}, [formState?.success, router]);
return (
<div>
<form action={formAction}>
<input type="text" name="name" min={3} max={50} placeholder="name" />
<input
type="text"
name="username"
min={3}
max={20}
placeholder="username"
/>
<input type="email" name="email" max={50} placeholder="email" />
<input
type="password"
name="password"
min={5}
max={15}
placeholder="password"
/>
<input
type="password"
name="passwordRepeat"
min={5}
max={15}
placeholder="password again"
/>
<input type="text" name="img" placeholder="imgSrc" />
<button>Register</button>
</form>
{formState?.success && <div className="toast">{formState?.message}</div>}
{!formState?.success && <div className="error">{formState?.message}</div>}
<Link href={"/login"}>
Already have an account? <b>Login</b>
</Link>
</div>
);
}After registiration, I keep getting error below even tough I have added secret. The error only occurs when i try to implement auto sign in feature
Uncaught MissingSecret: Missing secret, please set AUTH_SECRET or config.secret.
Thanks in advance