You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently there's no way to execute arbitrary code during the authentication process on the server.
This could be very handy for applications that use some kind of SQL database and needs to create a record their users, so they can later create relationships between the user and the rest of models on application.
How would it work?
One way to handle the execution of user defined functions on the server, would be adding a type to SSXServerRoutes union types such as:
hook must receive a Request as parameters, so the function can check internally if the user is authenticated and decide which path to take. It'll return a Promise<void> in order to enable async hooks, but to make sure the function doesn't return anything, since it wouldn't be used by ssx during the authentication.
the hook would be called right before the response to the client, to make sure it doesn't interfere on the other stuff the route is doing.
Should the whole route fail if hook throws?
I'd say yes, otherwise the client wouldn't know that something went wrong during the login, for example
Should the hook be executed if authentication fails, in the case of /ssx-login route?
Yes, if the function shouldn't be executed when the auth fails, req.ssx.verified should be used decide whether to continue or not.
Is there an existing issue for this?
Feature
Currently there's no way to execute arbitrary code during the authentication process on the server.
This could be very handy for applications that use some kind of SQL database and needs to create a record their users, so they can later create relationships between the user and the rest of models on application.
How would it work?
One way to handle the execution of user defined functions on the server, would be adding a type to
SSXServerRoutes
union types such as:hook
must receive aRequest
as parameters, so the function can check internally if the user is authenticated and decide which path to take. It'll return aPromise<void>
in order to enable async hooks, but to make sure the function doesn't return anything, since it wouldn't be used by ssx during the authentication.the
hook
would be called right before the response to the client, to make sure it doesn't interfere on the other stuff the route is doing.Should the whole route fail if hook throws?
I'd say yes, otherwise the client wouldn't know that something went wrong during the login, for example
Should the hook be executed if authentication fails, in the case of
/ssx-login
route?Yes, if the function shouldn't be executed when the auth fails,
req.ssx.verified
should be used decide whether to continue or not.Usage example
User Stories
As a developers I'd like to be able to create a record on the database if it's the first time a user is signing in on my app
The text was updated successfully, but these errors were encountered: