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
Hi, I've implemented middleware which populates user for each request. I wan't to have user object in ctxt.auth.user even if user is not logged in, e.g:
// App/Middleware/PopulateUser.tsexportdefaultclassPopulateUser{publicasynchandle({ auth, request }: HttpContextContract,next: ()=>Promise<void>){constuser=auth.userif(user){user.addDynamicRoles(constants.roles.dynamic.authenticated,constants.roles.dynamic.everyone,)// some more logic}else{auth.use().user=awaitcreateGuestUser(request)// not sure here if it legal way to override user, but it works}}}
It works OK, but when I try to use it in controllers, I got typescript errors:
I believe, it because user has optional modifier in typings:
@adonisjs/auth/build/adonis-typings/auth.d.ts:255
Is there a way to modify this interface and remove optional modifier from user field?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Hi, I've implemented middleware which populates user for each request. I wan't to have user object in
ctxt.auth.user
even if user is not logged in, e.g:It works OK, but when I try to use it in controllers, I got typescript errors:
I believe, it because
user
has optional modifier in typings:@adonisjs/auth/build/adonis-typings/auth.d.ts:255
Is there a way to modify this interface and remove optional modifier from
user
field?Thanks.
Beta Was this translation helpful? Give feedback.
All reactions