Chris NowickiOriginal post
Rank 2: Process
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:
TypeScript
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:
TypeScript
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?
Summary
A function triggers profile creation in DB on user creation. MagicURL option added to create user if not exist. Issue: the function doesn't run with MagicURL, only with email/password registration. Fix required to properly trigger the function with MagicURL.