We have a function that runs when a user is created. This function creates a profile for them in a collection in the DB.
I just added in MagicURL options. If a user does not exist with that email a new one is created via the createMagicURLToken.
here is the function:
export const createMagicURLToken = async (
email: IUser['email'],
): Promise<void> => {
try {
await account.createMagicURLToken(
ID.unique(),
email,
'http://localhost:3000/auth/magicURL',
);
} catch (error) {
console.error(error);
throw new Error('Error creating magic URL token');
}
};
and then when the user clicks the link in their email it uses this function:
export const createSessionFromMagicURLToken = async ({
userId,
secret,
}: {
userId: IUser['id'];
secret: string;
}): Promise<void> => {
try {
await account.createSession(userId, secret);
} catch (error) {
console.error(error);
throw new Error('Error creating session from magic URL token');
}
};
so the idea is if the user doesn't exist, and is created, then the Appwrite Function runs. This works on registering with email/password. But does not work with magicURL.
Thougts?
Recommended threads
- How to Avoid Double Requests in function...
I'm currently using Appwrite's `functions.createExecution` in my project. I want to avoid double requests when multiple actions (like searching or pagination) a...
- Send Email Verification With REST
I am using REST to create a user on the server side after receiving form data from the client. After the account is successfully created i wanted to send the v...
- Use different email hosts for different ...
Hello, I have 2 projects and i want to be able to set up email templates in the projects. Both projects will have different email host configurations. I see ...