You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
1.1 KiB
37 lines
1.1 KiB
3 years ago
|
import {Awaitable, JSONState, Maybe, Rehydratable} from '../util'
|
||
|
|
||
|
/** Value that can be used to uniquely identify a user. */
|
||
|
export type AuthenticatableIdentifier = string | number
|
||
|
|
||
|
/**
|
||
|
* Base class for entities that can be authenticated.
|
||
|
*/
|
||
|
export abstract class Authenticatable implements Rehydratable {
|
||
|
|
||
|
/** Get the unique identifier of the user. */
|
||
|
abstract getIdentifier(): AuthenticatableIdentifier
|
||
|
|
||
|
/** Get the human-readable identifier of the user. */
|
||
|
abstract getDisplayIdentifier(): string
|
||
|
|
||
|
abstract dehydrate(): Promise<JSONState>
|
||
|
|
||
|
abstract rehydrate(state: JSONState): Awaitable<void>
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Base class for a repository that stores and recalls users.
|
||
|
*/
|
||
|
export abstract class AuthenticatableRepository {
|
||
|
|
||
|
/** Look up the user by their unique identifier. */
|
||
|
abstract getByIdentifier(id: AuthenticatableIdentifier): Awaitable<Maybe<Authenticatable>>
|
||
|
|
||
|
/**
|
||
|
* Attempt to look up and verify a user by their credentials.
|
||
|
* Returns the user if the credentials are valid.
|
||
|
* @param credentials
|
||
|
*/
|
||
|
abstract getByCredentials(credentials: Record<string, string>): Awaitable<Maybe<Authenticatable>>
|
||
|
}
|