discorrrdbomba
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. discorrrdbomba
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
- The current user is not authorized to pe...
I want to create a document associated with user after log in with OAuth. The user were logged in, but Appwrite said user is unauthorized. User is logged in wi...
- self-hosted auth: /v1/account 404 on saf...
Project created in React/Next.js, Appwrite version 1.6.0. Authentication works in all browsers except Safari (ios), where an attempt to connect to {endpoint}/v1...
- Having issues with login via CLI
``` ~/appwrite appwrite login --endpoint https://localhost/v1 --verbose ? Enter your email myvalidemai...