I'm using client side Appwrite for user registration. This is my current code.
import { ID } from "appwrite";
import { account } from "$lib/appwrite";
const createUserService = () => {
async function register(email: string) {
try {
const sessionToken = await account.createMagicURLToken(ID.unique(), email, "my url", true);
console.log(sessionToken);
} catch (error: any) {
console.log(error);
throw new Error(error);
}
}
return {
register
};
};
const userService = createUserService();
export default userService;
When I call userService.register with my email address. I'm getting this response.
{
$createdAt: "2024-05-05T21:00:04.767+00:00"
$id: "6637f354bb4e13d0c723"
expire: "2024-05-05T22:00:04.767+00:00"
phrase: "Enthusiastic zebra"
secret: ""
userId: "6637f286001edeb788e0"
}
That secret key is empty. Why is this happening?
The secret value will only be returned if the request was made by a client that has an API key set https://appwrite.io/docs/references/cloud/models/session#:~:text=secret,an%20API%20key
Should I manually make a secret from the client?
It is because I cannot achieve a login without secret
Oh my bad, I misread the code, let me take a closer look at it as I referred to the wrong method
It looks like it's still the case though, where the client needs to be created using an API key https://appwrite.io/docs/references/cloud/models/token#:~:text=Token%20secret%20key.%20This%20will%20return%20an%20empty%20string%20unless%20the%20response%20is%20returned%20using%20an%20API%20key%20or%20as%20part%20of%20a%20webhook%20payload.
You'll need to use a client that has been created using an API key from the Appwrite Console
But I cannot create a Client with API_KEY on client side
There is no method called setKey()
Where are you trying to use the secret value?
For login
login method requires 2 parameters - userId, secret
This function generates an link that is sent to the user in an email, the values should be included in the URL that is sent in the email
???
Email is not being sent
I tried 100 times but didn't get any emails
Have you setup emails in the Appwrite Console?
Oh, where do I setup them?
The link I just sent should walk you through setting up an SMTP provider
Recommended threads
- is `account.get()` safe to be used in th...
I want to user's `id` for authentication. However, a while ago I was told in this server not to use `account.get()` and instead add user preferences for that us...
- Usage of the new Client() and dealing wi...
Hey guys, just a quick one - we had some web traffic the other day and it ended up bombing out - To put in perspective of how the app works, we have a Nuxt Ap...
- [Beginner] CLI --queries Syntax Error & ...
Hi everyone! I am a beginner with Appwrite and trying to use the CLI, but I'm stuck with a syntax error. Any guidance would be greatly appreciated! 🙏 **Enviro...