I use something like this to create a signUp function:
TypeScript
const verifyUrl = `${window.location.protocol}//${window.location.host}/${locale}/dashboard`;
await account(locale).create(
ID.unique(),
email,
password,
name ? name : undefined
);
const session = await account(locale).createEmailPasswordSession(
email,
password
);
console.log(session);
await account(locale).createVerification(verifyUrl);
await account(locale).deleteSession(session.$id);
setShowSuccess(true);
} catch (err: any) {
if (isAppwriteException(err)) {...```
...now the email get sent to the users email address successfully, including the redirect url.
A click to the redirect url opens the browser and the dashboard as intended. Inside of my nextjs 14 app's layout.js file I've got an AuthContext Provider wrapped around the app, which "onUseEffect" triggers the confirmVerification function (internal wrapper for updateVerification), which almost also works as intended - almost. The user gets verified (green tag in the console), but the updateVerification returns 401 stating "Invalid token passed in the request". See comment for the rest of my question -->
TL;DR
Developers are facing issues with the confirmVerification function while attempting to update verification and create a session. The issue may be related to timing/instances of the client/account being used. A possible solution could be to ensure the user is verified before triggering the function. The updateVerification function returns a 401 error stating "Invalid token passed in the request." This could be due to incorrect token handling or authentication issues. Double-check the token handling logic to troubleshoot the error.Here the confirmVerification function (internal wrapper for updateVerification) from within AuthProvider:
TypeScript
const userId = useSearchParams().get("userId") || "";
const secret = useSearchParams().get("secret") || "";
// ConfirmVerification
const confirmVerification = async (): Promise<void> => {
try {
await account.updateVerification(userId, secret);
const responseSession = await account.createSession(userId, secret);
const responseAccount = await account.get();
setSession(responseSession);
setUser(responseAccount);
toasty({
variant: "success",
header: (
<>
{tAuth("welcome")}{" "}
<span
style={{
display: "inline-block",
transform: "rotateY(180deg)",
marginLeft: 2,
}}>
👋
</span>
</>
),
msg: `${tAuth("signed_in_as")} ${"email"}`,
});
} catch (err: any) {
if (isAppwriteException(err)) {
toasty({
variant: "error",
buttonChildren: tAuth("dismiss_or_understood"),
header: tAuth("auth_error"),
msg: err.message,
});
} else {
toasty({
variant: "error",
buttonChildren: tAuth("dismiss_or_understood"),
header: tAuth("general_error"),
msg: JSON.stringify(err),
});
}
}
};
useEffect(() => {
if (pathname === "/dashboard" && userId && secret) {
confirmVerification();
}
}, []);```
Any Idea why this does not work out? Is it probably bcs of using wrong timing/instances of client/account?
Recommended threads
- Payment problems
Its really beginning to frustrate me, last month I was on Pro plan on Appwrite cloud, I chose the option to downgrade next month(this one) to Free plan, and tha...
- Function executions via custom domain fr...
Aplogies if this was asked already. I'm self-hosting 1.9 on a self-hosted instance of Dokploy. I've made the necessary adjustments to the original compose file ...
- Running into a server error on my self-h...
Hey everyone, I'm running into a server error on my self-hosted setup after updating to v1.19.0. The issue only happens during user creation and deletion. Ever...