onSuccess bug?

onSuccess requires 1s setTimeout before redirecting, otherwise the session is null. the documentation doesn't mention this, I was expecting that onSuccess means the session was already set, is this a bug?
await authClient.signIn.email(
{
email: value.email,
password: value.password,
},
{
onSuccess: () => {
const SIGN_IN_SUCCESS_REDIRECT_DELAY_MS = 1000;
setTimeout(() => {
router.push("/dashboard");
toast.success("Sign in successful");
}, SIGN_IN_SUCCESS_REDIRECT_DELAY_MS);
await authClient.signIn.email(
{
email: value.email,
password: value.password,
},
{
onSuccess: () => {
const SIGN_IN_SUCCESS_REDIRECT_DELAY_MS = 1000;
setTimeout(() => {
router.push("/dashboard");
toast.success("Sign in successful");
}, SIGN_IN_SUCCESS_REDIRECT_DELAY_MS);
const { data: session, isPending } = authClient.useSession();

useEffect(() => {
if (!(session || isPending)) {
router.push("/login");
}
}, [session, isPending]);
const { data: session, isPending } = authClient.useSession();

useEffect(() => {
if (!(session || isPending)) {
router.push("/login");
}
}, [session, isPending]);
1 Reply
Jigz
JigzOP4w ago
for context, this only happens on next static export, this isn't an issue on server rendered next.

Did you find this page helpful?