app/Middleware/SilentAuth.ts   A
last analyzed

Complexity

Total Complexity 2
Complexity/F 1

Size

Lines of Code 22
Function Count 2

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 8
mnd 0
bc 0
fnc 2
dl 0
loc 22
bpm 0
cpm 1
noi 0
c 0
b 0
f 0
rs 10

1 Function

Rating   Name   Duplication   Size   Complexity  
A SilentAuthMiddleware.handle 0 10 1
1
import type { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
2
3
/**
4
 * Silent auth middleware can be used as a global middleware to silent check
5
 * if the user is logged-in or not.
6
 *
7
 * The request continues as usual, even when the user is not logged-in.
8
 */
9
export default class SilentAuthMiddleware {
10
  /**
11
   * Handle request
12
   */
13
  public async handle({ auth }: HttpContextContract, next: () => Promise<void>) {
14
    /**
15
     * Check if user is logged-in or not. If yes, then `ctx.auth.user` will be
16
     * set to the instance of the currently logged in user.
17
     */
18
    await auth.check()
19
    await next()
20
  }
21
}
22