Back

Some questions regarding magic links

  • 0
  • Self Hosted
  • Accounts
  • Web
Marius Bolik
9 Aug, 2023, 16:54

Question 1: How to use the megic link feature without user id? In the web sdk, the user id is required to send a magic link. Is there a way to use createMagicURLSession only with the email address of a user?

Question 2: Can I use Functions to send a magic link? I want to use appwrite functions to send a magic link to a user through a custom mail server. Which method of the server sdk to I have to use to generate the magic link?

Kind regards, Marius

TL;DR
1. The `userId` parameter is required for the `createMagicURLSession` endpoint. However, if the specified email already exists in your project, the `userId` doesn't matter. You can pass a unique ID using the `ID.unique()` Appwrite SDK helper. 2. Custom email templates are not currently supported in Appwrite Cloud. You can experiment with using a self-hosted instance and modifying the docker compose file, but in Appwrite Cloud, SMTP and templates are handled by the Appwrite team. Question 1: Using the web SDK, the `createMagicURLSession` endpoint requires a `userId`. It is
safwan
9 Aug, 2023, 17:09
  1. The userId in the createMagicURLSession endpoint is something that needs to be passed in, to make sure there is a unique ID attached to the user. You can use the ID.unique() helper that comes with the appwrite sdk, to generate and assign a unique ID on the go.
  2. As far as I know this is not possible. Why don't you set up your mail server in Appwrite's env file, and use it as is?
Marius Bolik
9 Aug, 2023, 18:24

Thank you for the fast response!

  1. I want to provide a passwordless login to existing users. The user should just enter his/her email and should be able to receive a login link. Isn't that possible?
  2. I am using the cloud version and I also want to use custom html in the email. I haved panned to use resend.com as email provider.
safwan
9 Aug, 2023, 19:15

No issues πŸ˜„

Okay so I looked at the code, and it seems like the userId doesn't matter if the email already exists in your project. So you should be able to do something like this:

TypeScript
const promise = account.createMagicURLSession(ID.unique(), 'abc@example.com');

And the userId would come into play, only if a user with the specified email doesn't already exist.

As for your second point, custom email templates aren't a feature yet. You can play around with the docker compose file in a self-hosted instance, but can't really do much in Appwrite Cloud, as SMTP and templates are handled by the Appwrite team.

safwan
9 Aug, 2023, 19:15

Let me know if you have any more questions!

Marius Bolik
12 Aug, 2023, 19:30

This was very helpful. Thank you @safwan!

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