-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refacto: moves types to a specific file
- Loading branch information
Showing
3 changed files
with
49 additions
and
46 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { symbols } from '@adonisjs/auth' | ||
|
||
/** | ||
* The bridge between the User provider and the | ||
* Guard | ||
*/ | ||
export type JwtGuardUser<RealUser> = { | ||
/** | ||
* Returns the unique ID of the user | ||
*/ | ||
getId(): string | number | BigInt | ||
|
||
/** | ||
* Returns the original user object | ||
*/ | ||
getOriginal(): RealUser | ||
} | ||
|
||
/** | ||
* The interface for the UserProvider accepted by the | ||
* JWT guard. | ||
*/ | ||
export interface JwtUserProviderContract<RealUser> { | ||
/** | ||
* A property the guard implementation can use to infer | ||
* the data type of the actual user (aka RealUser) | ||
*/ | ||
[symbols.PROVIDER_REAL_USER]: RealUser | ||
|
||
/** | ||
* Create a user object that acts as an adapter between | ||
* the guard and real user value. | ||
*/ | ||
createUserForGuard(user: RealUser): Promise<JwtGuardUser<RealUser>> | ||
|
||
/** | ||
* Find a user by their id. | ||
*/ | ||
findById(identifier: string | number | BigInt): Promise<JwtGuardUser<RealUser> | null> | ||
} | ||
|
||
export type JwtGuardOptions<RealUser extends any = unknown> = { | ||
secret: string | ||
expiresIn?: number | string | ||
useCookies?: boolean | ||
content?: (user: JwtGuardUser<RealUser>) => Record<string, any> | ||
} |