Questions about signup/signout in Next

The docs have this example code for email/password signup and signout:
// Signup
import { authClient } from "@/lib/auth-client"; //import the auth client

const { data, error } = await authClient.signUp.email({
email, // user email address
password, // user password -> min 8 characters by default
name, // user display name
image, // User image URL (optional)
callbackURL: "/dashboard" // A URL to redirect to after the user verifies their email (optional)
}, {
onRequest: (ctx) => {
//show loading
},
onSuccess: (ctx) => {
//redirect to the dashboard or sign in page
},
onError: (ctx) => {
// display the error message
alert(ctx.error.message);
},
});

// Signout
await authClient.signOut();
// Signup
import { authClient } from "@/lib/auth-client"; //import the auth client

const { data, error } = await authClient.signUp.email({
email, // user email address
password, // user password -> min 8 characters by default
name, // user display name
image, // User image URL (optional)
callbackURL: "/dashboard" // A URL to redirect to after the user verifies their email (optional)
}, {
onRequest: (ctx) => {
//show loading
},
onSuccess: (ctx) => {
//redirect to the dashboard or sign in page
},
onError: (ctx) => {
// display the error message
alert(ctx.error.message);
},
});

// Signout
await authClient.signOut();
1) callbackURL does not seem to do anything, is it deprecated or something or do I just manuallt redirect with next/navigation. 2) Signout does not refresh useSession so my UI appears as the user is still logged in. Do I need to manually refresh the page or is there a built in way?
2 Replies
Mnigos
Mnigos3mo ago
1. Not sure why, but it doesn't work. I tried in nextjs and router router. Just use next navigation. 2. use router.refresh()
sebastian
sebastian3mo ago
sign-out should automatically refresh the ui state. If it doesnt do that you can export refetch from authClient and use that instead of the router.refresh() which should be used in edge-cases

Did you find this page helpful?