Feat(auth): Remove auth provider entity (#6314)
**What** - remove auth provider entity **Why** - The auth provider entity was not really used anywhere **How** - Keeping loader behavior as is but removing the Co-authored-by: Sebastian Rindom <7554214+srindom@users.noreply.github.com>
This commit is contained in:
@@ -5,22 +5,34 @@ import { MedusaError } from "../common"
|
||||
export abstract class AbstractAuthModuleProvider {
|
||||
public static PROVIDER: string
|
||||
public static DISPLAY_NAME: string
|
||||
protected readonly scopes_: Record<string, AuthProviderScope>
|
||||
|
||||
protected readonly container_: any
|
||||
protected scopeConfig_: AuthProviderScope
|
||||
protected scope_: string
|
||||
|
||||
private readonly scopes_: Record<string, AuthProviderScope>
|
||||
|
||||
public get provider() {
|
||||
return (this.constructor as Function & { PROVIDER: string }).PROVIDER
|
||||
return (this.constructor as typeof AbstractAuthModuleProvider).PROVIDER
|
||||
}
|
||||
|
||||
public get displayName() {
|
||||
return (this.constructor as Function & { DISPLAY_NAME: string })
|
||||
.DISPLAY_NAME
|
||||
return (this.constructor as typeof AbstractAuthModuleProvider).DISPLAY_NAME
|
||||
}
|
||||
|
||||
protected constructor({ scopes }) {
|
||||
protected constructor(
|
||||
{ scopes },
|
||||
config: { provider: string; displayName: string }
|
||||
) {
|
||||
this.container_ = arguments[0]
|
||||
this.scopes_ = scopes
|
||||
;(this.constructor as typeof AbstractAuthModuleProvider).PROVIDER ??=
|
||||
config.provider
|
||||
;(this.constructor as typeof AbstractAuthModuleProvider).DISPLAY_NAME ??=
|
||||
config.displayName
|
||||
}
|
||||
|
||||
public validateScope(scope) {
|
||||
private validateScope(scope) {
|
||||
if (!this.scopes_[scope]) {
|
||||
throw new MedusaError(
|
||||
MedusaError.Types.INVALID_ARGUMENT,
|
||||
@@ -29,6 +41,16 @@ export abstract class AbstractAuthModuleProvider {
|
||||
}
|
||||
}
|
||||
|
||||
public withScope(scope: string) {
|
||||
this.validateScope(scope)
|
||||
|
||||
const cloned = new (this.constructor as any)(this.container_)
|
||||
cloned.scope_ = scope
|
||||
cloned.scopeConfg_ = this.scopes_[scope]
|
||||
|
||||
return cloned
|
||||
}
|
||||
|
||||
abstract authenticate(
|
||||
data: Record<string, unknown>
|
||||
): Promise<AuthenticationResponse>
|
||||
|
||||
Reference in New Issue
Block a user