-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9ed0e90
commit 4a4f644
Showing
10 changed files
with
1,571 additions
and
3,914 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import type { HttpContext } from '@adonisjs/core/http' | ||
import type { NextFn } from '@adonisjs/core/types/http' | ||
import type { Authenticators } from '@adonisjs/auth/types' | ||
|
||
/** | ||
* Guest middleware is used to deny access to routes that should | ||
* be accessed by unauthenticated users. | ||
* | ||
* For example, the login page should not be accessible if the user | ||
* is already logged-in | ||
*/ | ||
export default class GuestMiddleware { | ||
/** | ||
* The URL to redirect to when user is logged-in | ||
*/ | ||
redirectTo = '/' | ||
|
||
async handle( | ||
ctx: HttpContext, | ||
next: NextFn, | ||
options: { guards?: (keyof Authenticators)[] } = {} | ||
) { | ||
for (let guard of options.guards || [ctx.auth.defaultGuard]) { | ||
if (await ctx.auth.use(guard).check()) { | ||
return ctx.response.redirect(this.redirectTo, true) | ||
} | ||
} | ||
|
||
return next() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import type { HttpContext } from '@adonisjs/core/http' | ||
import type { NextFn } from '@adonisjs/core/types/http' | ||
|
||
/** | ||
* Silent auth middleware can be used as a global middleware to silent check | ||
* if the user is logged-in or not. | ||
* | ||
* The request continues as usual, even when the user is not logged-in. | ||
*/ | ||
export default class SilentAuthMiddleware { | ||
async handle(ctx: HttpContext, next: NextFn) { | ||
await ctx.auth.check() | ||
|
||
return next() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.