I want to use redirect only when signIn(). I have tried several methods.
This method make my app will redirect on both sign in and sign out. Not for my situation.
callbacks: {
async redirect({ url, baseUrl }) {
return "/account/loadingregister";
},
},
<button onClick={() => signIn({ callbackUrl: "http://localhost:3000/abc" })}>
Sign In
</button>
<button onClick={() => signOut({ callbackUrl: "http://localhost:3000/foo" })}>
Sign Out
</button>
So, how can I redirect only in sign in function?
import { signOut } from "next-auth/react";
const logoutHandler = () => {
signOut();
};
<button onClick={logoutHandler}>
Sign Out
</button>
Finally, I found the answer. Need to use async function to redirect to other page after signIn.
const handleSignIn = async () => {
await signIn("google", {
callbackUrl: "/",
});
};
//component:
<button onClick={() => handleSignIn()}>Sign In</button>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.