I want to run a function when a user logs in to put a unique code onto the user. Then I can use this code to authenticate subsequent requests. I want to do something very similar to the weak2FA example on this page (https://v3.docs.apostrophecms.org/guide/custom-login-requirements.html#the-server-side), but I don't know how to structure the code so that it will not return the component to the frontend. Right now I get an error on the frontend because it's expecting a Vue component. I want the user to just enter in their username and password, and that's it. Then upon login it will add a code to the user model. Nothing more.
Does anyone know how this can be done?
Since you're talking about doing this in the context of the built-in login page, you can take advantage of the
afterSessionLoginpromise event, like this:This code goes straight to MongoDB to set one property of the user document quickly without race conditions or permissions checks.