Back

`secrets` is not generated after Appwrite registration

  • 0
  • Self Hosted
  • Auth
  • Web
Stefan
5 May, 2024, 21:01

I'm using client side Appwrite for user registration. This is my current code.

TypeScript
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.

TypeScript
{
  $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?

TL;DR
Developers are having trouble generating the `secret` after registering with Appwrite. The issue seems to arise from the lack of `secret` in the returned data. The `secret` will only be returned if the request was made by a client with an API key set. Ensure clients are created using an API key from the Appwrite Console for successful login.
Ryan
5 May, 2024, 21:15

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

Stefan
5 May, 2024, 21:23

Should I manually make a secret from the client?

Stefan
5 May, 2024, 21:26

It is because I cannot achieve a login without secret

Ryan
5 May, 2024, 21:26

Oh my bad, I misread the code, let me take a closer look at it as I referred to the wrong method

Ryan
5 May, 2024, 21:28

You'll need to use a client that has been created using an API key from the Appwrite Console

Stefan
5 May, 2024, 21:30

But I cannot create a Client with API_KEY on client side

Stefan
5 May, 2024, 21:30

There is no method called setKey()

Ryan
5 May, 2024, 21:31

Where are you trying to use the secret value?

Stefan
5 May, 2024, 21:32

For login

Stefan
5 May, 2024, 21:32

login method requires 2 parameters - userId, secret

Ryan
5 May, 2024, 21:32

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

Stefan
5 May, 2024, 21:33

???

Stefan
5 May, 2024, 21:33

Email is not being sent

Stefan
5 May, 2024, 21:33

I tried 100 times but didn't get any emails

Ryan
5 May, 2024, 21:33

Have you setup emails in the Appwrite Console?

Stefan
5 May, 2024, 21:33

Oh, where do I setup them?

Ryan
5 May, 2024, 21:34

The link I just sent should walk you through setting up an SMTP provider

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more