Skip to content
Discussion options

You must be logged in to vote

Yep, you can reach through to the underlying request object and set it directly. Here's an example piggybacking off the SilentAuth middleware.

export default class SilentAuthMiddleware {
  /**
   * Handle request
   */
  public async handle({ auth, request }: HttpContextContract, next: () => Promise<void>) {
    /**
     * Check if user is logged-in or not. If yes, then `ctx.auth.user` will be
     * set to the instance of the currently logged in user.
     */

    // try to get token from cookies, if found, set authorization
    const token = request.cookie('auth-session')
    if (token) {
      request.request.headers['authorization'] = `Bearer ${token}`
    }

    await auth.check()
    

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@franklinvillalobos
Comment options

Comment options

You must be logged in to vote
1 reply
@franklinvillalobos
Comment options

Answer selected by franklinvillalobos
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
3 participants