node_modules/@adonisjs/auth/src/Schemes/Jwt.js
/**
   * Check if user is authenticated for the current HTTP request or not. This
   * method will read the token from the `Authorization` header or fallbacks
   * to the `token` input field.
   *
   * Consider user as successfully authenticated, if this
   * method doesn't throws an exception.
   *
   * @method check
   * @async
   *
   * @return {Boolean}
   *
   * @example
   * ```js
   * try {
   *   await auth.check()
   * } catch (error) {
   *   // invalid jwt token
   * }
   * ```
   */
Check if user is authenticated for the current HTTP request or not. This
method will read the token from the `Authorization` header or fallbacks
to the `token` input field.

Consider user as successfully authenticated, if this
method doesn't throws an exception.

@method check
@async

@return {Boolean}


Check if user is authenticated for the current HTTP request or not . This method will read the token from the ` Authorization ` header or fallbacks to the ` token ` input field . Consider user as successfully authenticated if this method doesn ' t throws an exception . @method check @async @return { Boolean }
async check () {
    if (this.user) {
      return true
    }
    const token = this.getAuthHeader()
    try {
      this.jwtPayload = await this._verifyToken(token)
    } catch ({ name, message }) {
      if (name === 'TokenExpiredError') {
        throw CE.ExpiredJwtToken.invoke()
      }
      throw CE.InvalidJwtToken.invoke(message)
    }
    this.user = await this._serializerInstance.findById(this.jwtPayload.uid)
    if (!this.user) {
      throw CE.InvalidJwtToken.invoke()
    }
    return true
  }
async check ( ) { if ( this . user ) { return true } const token = this . getAuthHeader ( ) try { this . jwtPayload = await this . _verifyToken ( token ) } catch ( { name , message } ) { if ( name === 'TokenExpiredError' ) { throw CE . ExpiredJwtToken . invoke ( ) } throw CE . InvalidJwtToken . invoke ( message ) } this . user = await this . _serializerInstance . findById ( this . jwtPayload . uid ) if ( ! this . user ) { throw CE . InvalidJwtToken . invoke ( ) } return true }
Check if user is authenticated for the current HTTP request or not.
Check if user is authenticated for the current HTTP request or not .
/**
     * Verify jwt token and wrap exception inside custom
     * exception classes
     */ /**
     * Throw exception when user is not found
     */