-
-
Notifications
You must be signed in to change notification settings - Fork 63
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
db93550
commit e2f20fc
Showing
8 changed files
with
229 additions
and
66 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import type { HttpContext } from '@adonisjs/core/http' | ||
import type { NextFn } from '@adonisjs/core/types/http' | ||
import type { Authenticators } from '@adonisjs/auth/types' | ||
|
||
/** | ||
* Options accepted by the middleware options | ||
*/ | ||
export type AuthMiddlewareOptions = { | ||
guards?: (keyof Authenticators)[] | ||
redirectTo?: string | ||
} | ||
|
||
export default class AuthMiddleware { | ||
async handle(ctx: HttpContext, next: NextFn, options: AuthMiddlewareOptions = {}) { | ||
await ctx.auth.authenticateUsing(options.guards, options) | ||
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,37 @@ | ||
/// <reference types="@adonisjs/core/providers/edge_provider" /> | ||
|
||
import auth from '@adonisjs/auth/services/main' | ||
import type { HttpContext } from '@adonisjs/core/http' | ||
import type { NextFn } from '@adonisjs/core/types/http' | ||
|
||
/** | ||
* The "InitializeAuthMiddleware" is used to create a request | ||
* specific authenticator instance for every HTTP request. | ||
* | ||
* This middleware does not protect routes from unauthenticated | ||
* users. Please use the "auth" middleware for that. | ||
*/ | ||
export default class InitializeAuthMiddleware { | ||
async handle(ctx: HttpContext, next: NextFn) { | ||
/** | ||
* Initialize the authenticator for the current HTTP | ||
* request | ||
*/ | ||
ctx.auth = auth.createAuthenticator(ctx) | ||
|
||
/** | ||
* Sharing authenticator with templates | ||
*/ | ||
if ('view' in ctx) { | ||
ctx.view.share({ auth: ctx.auth }) | ||
} | ||
|
||
return next() | ||
} | ||
} | ||
|
||
declare module '@adonisjs/core/http' { | ||
export interface HttpContext { | ||
auth: ReturnType<(typeof auth)['createAuthenticator']> | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.
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