Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide user authentication information on 'account.create' event #1373

Open
gwesterman opened this issue Jul 10, 2021 · 4 comments
Open

Provide user authentication information on 'account.create' event #1373

gwesterman opened this issue Jul 10, 2021 · 4 comments
Labels
enhancement New feature or request product / auth Fixes and upgrades for the Appwrite Auth / Users / Teams services. product / functions Fixes and upgrades for the Appwrite Functions.

Comments

@gwesterman
Copy link

🚀 Feature

I'm trying to achieve the following: When a user creates an account I want the verification email to be sent by a server side function and not from within the client side callback.

Have you spent some time to check if this issue has been raised before?

I've used Google and discussed the issue with @eldadfux on Discord. As far as I can tell this has not yet been proposed or discussed.

Have you read the Code of Conduct?

Yes.

Pitch

For this to work one needs to set a valid JWT for the user inside of the function. The JWT is provided through the 'APPWRITE_FUNCTION_JWT' environment variable.

Currently the 'account.create' event does not set this variable since the user it not authenticated when account.create() is called.

Here's the code I'm deploying as a function:

const sdk = require('node-appwrite');

let client = new sdk.Client();

client
.setEndpoint(process.env.APPWRITE_ENDPOINT)
.setProject(process.env.APPWRITE_FUNCTION_PROJECT_ID)
.setJWT(process.env.APPWRITE_FUNCTION_JWT);

const account = new sdk.Account(client);

account.createVerification('http:https://localhost:4200').then(response => {
console.log('createVerification success', response);
}, (error ) => {
console.error('createVerification error', error);
})

Currently process.env.APPWRITE_FUNCTION_JWT is 'null'.

This can also come in handy in other scenarios.

@TorstenDittmann TorstenDittmann added the enhancement New feature or request label Aug 13, 2021
@TorstenDittmann
Copy link
Contributor

As of right now, we are only passing the JWT if the function was executed by the user itself. But I can understand how in this particular case it could be really beneficial.

This is also where the problem is then - it would be completely out of the ordinary and wouldn't follow any structure to have a JWT with only this call by an event.

Can you think of any more events where this might be nice to have? Maybe all account events? 🤔

@rdmchr
Copy link
Contributor

rdmchr commented Sep 16, 2021

How much trouble would it be to pass the JWT for each event? I feel like that would be the most consistent and easy to understand. Also having that JWT always accessible doesn't do any harm, does it?

@sammichael25
Copy link

As of right now, we are only passing the JWT if the function was executed by the user itself. But I can understand how in this particular case it could be really beneficial.

This is also where the problem is then - it would be completely out of the ordinary and wouldn't follow any structure to have a JWT with only this call by an event.

Can you think of any more events where this might be nice to have? Maybe all account events? 🤔

Agreed, I'm currently trying to conduct email verification checks using the on session create event to trigger a function but the JWT isn't set. Having the JWT available for all account events could help other use cases too.

@stnguyen90 stnguyen90 added the product / functions Fixes and upgrades for the Appwrite Functions. label Mar 8, 2023
@stnguyen90 stnguyen90 added the product / auth Fixes and upgrades for the Appwrite Auth / Users / Teams services. label Mar 28, 2023
@stnguyen90
Copy link
Contributor

In Appwrite 1.5, it's now possible to create a session for a user server-side so you can do this and then have a session to call the account.createVerification() method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request product / auth Fixes and upgrades for the Appwrite Auth / Users / Teams services. product / functions Fixes and upgrades for the Appwrite Functions.
Projects
None yet
Development

No branches or pull requests

5 participants