Detecting new login

how can you detect a new user login, such that you can log it, etc.?
I don’t see anything on the AppUser business object (in loopback 4 base library)
Is there an event of something or some other way to detect this?

The AppUser business object in the LoopBack 4 Base Library has an emitAppUserCreated behavior that does this:

this.app.emit('AppUser Created', appUser);

If you want to do something when a user accesses the system for the first time, you can create an after start behavior (app or business object) that does this:

this.app.on('AppUser Created', async (appUser)=>{
  // do something here
});

Thanks. But what about when a user authenticates (e.g. new login to the app), is there a way to be informed when this happens? Like maybe something in the App components gets driven?

The event I described is only emitted the first time a user logs in to the system. Is that what you are looking for?

That’s useful, and I wanted to know when a user begins a new session, like the first time they login for the day…to capture last login, show any outstanding messages they have, etc.

This can be added as application logic by adding a little custom code to the LoopBack.io sequence.ts file (or one of the files it calls). This is basically inserting middleware that each API request is passed to. We use this pattern to track activity where we insert an activity record into the database to track user activity.

From a purely design point of view, you would have to figure out what “first for the day” means - especially for an app that is used around the world.