@@ -4,22 +4,23 @@ import { IHttpServer } from "adminforth";
4
4
import { randomUUID } from 'crypto' ;
5
5
import type { OAuth2Adapter } from "adminforth" ;
6
6
import { AdminForthDataTypes } from "adminforth" ;
7
+ import type { HttpExtra } from './types.js' ;
7
8
8
- interface OAuth2SSOPluginOptions {
9
+ interface OAuthPluginOptions {
9
10
emailField : string ;
10
11
emailConfirmedField ?: string ;
11
12
adapters : OAuth2Adapter [ ] ;
12
13
}
13
14
14
- export class OAuth2SSOPlugin extends AdminForthPlugin {
15
- private options : OAuth2SSOPluginOptions ;
16
- private adminforth : IAdminForth ;
15
+ export class OAuthPlugin extends AdminForthPlugin {
16
+ private options : OAuthPluginOptions ;
17
+ public adminforth : IAdminForth ;
17
18
private resource : AdminForthResource ;
18
19
19
- constructor ( options : OAuth2SSOPluginOptions ) {
20
+ constructor ( options : OAuthPluginOptions ) {
20
21
super ( options , import . meta. url ) ;
21
22
if ( ! options . emailField ) {
22
- throw new Error ( 'OAuth2SSOPlugin : emailField is required' ) ;
23
+ throw new Error ( 'OAuthPlugin : emailField is required' ) ;
23
24
}
24
25
this . options = options ;
25
26
}
@@ -32,26 +33,26 @@ export class OAuth2SSOPlugin extends AdminForthPlugin {
32
33
33
34
// Validate emailField exists in resource
34
35
if ( ! resource . columns . find ( col => col . name === this . options . emailField ) ) {
35
- throw new Error ( `OAuth2SSOPlugin : emailField "${ this . options . emailField } " not found in resource columns` ) ;
36
+ throw new Error ( `OAuthPlugin : emailField "${ this . options . emailField } " not found in resource columns` ) ;
36
37
}
37
38
38
39
// Validate emailConfirmedField if provided
39
40
if ( this . options . emailConfirmedField ) {
40
41
const confirmedField = resource . columns . find ( col => col . name === this . options . emailConfirmedField ) ;
41
42
if ( ! confirmedField ) {
42
- throw new Error ( `OAuth2SSOPlugin : emailConfirmedField "${ this . options . emailConfirmedField } " not found in resource columns` ) ;
43
+ throw new Error ( `OAuthPlugin : emailConfirmedField "${ this . options . emailConfirmedField } " not found in resource columns` ) ;
43
44
}
44
45
if ( confirmedField . type !== AdminForthDataTypes . BOOLEAN ) {
45
- throw new Error ( `OAuth2SSOPlugin : emailConfirmedField "${ this . options . emailConfirmedField } " must be a boolean field` ) ;
46
+ throw new Error ( `OAuthPlugin : emailConfirmedField "${ this . options . emailConfirmedField } " must be a boolean field` ) ;
46
47
}
47
48
}
48
49
49
50
// Make sure customization and loginPageInjections exist
50
- if ( ! adminforth . config . customization ) {
51
- adminforth . config . customization = { } ;
52
- }
53
- if ( ! adminforth . config . customization . loginPageInjections ) {
54
- adminforth . config . customization . loginPageInjections = { underInputs : [ ] } ;
51
+ if ( ! adminforth . config . customization ?. loginPageInjections ) {
52
+ adminforth . config . customization = {
53
+ ... adminforth . config . customization ,
54
+ loginPageInjections : { underInputs : [ ] }
55
+ } ;
55
56
}
56
57
57
58
// Register the component with the correct plugin path
0 commit comments