@@ -9,6 +9,7 @@ import type { HttpExtra } from './types.js';
99interface OAuthPluginOptions {
1010 emailField : string ;
1111 emailConfirmedField ?: string ;
12+ userFullNameField ?: string ;
1213 adapters : OAuth2Adapter [ ] ;
1314 buttonText ?: string ;
1415 iconOnly ?: boolean ;
@@ -77,6 +78,13 @@ export default class OAuthPlugin extends AdminForthPlugin {
7778 }
7879 }
7980
81+ if ( this . options . userFullNameField ) {
82+ const nameField = resource . columns . find ( col => col . name === this . options . userFullNameField ) ;
83+ if ( ! nameField ) {
84+ throw new Error ( `OAuthPlugin: userFullNameField "${ this . options . userFullNameField } " not found in resource columns` ) ;
85+ }
86+ }
87+
8088 // Make sure customization and loginPageInjections exist
8189 if ( ! adminforth . config . customization ?. loginPageInjections ) {
8290 adminforth . config . customization = {
@@ -200,6 +208,16 @@ export default class OAuthPlugin extends AdminForthPlugin {
200208 user = await this . adminforth . resource ( this . resource . resourceId ) . create ( createData ) ;
201209 }
202210
211+ if ( this . options . userFullNameField && userInfo . fullName ) {
212+ const userResourcePrimaryKey = this . resource . columns . find ( col => col . primaryKey ) ?. name ;
213+ const userFullName = user [ this . options . userFullNameField ] ;
214+ if ( userFullName && userFullName !== userInfo . fullName ) {
215+ await this . adminforth . resource ( this . resource . resourceId ) . update ( user [ userResourcePrimaryKey ] , {
216+ [ this . options . userFullNameField ] : userInfo . fullName
217+ } ) ;
218+ }
219+ }
220+
203221 return await this . doLogin ( userInfo . email , response , {
204222 headers,
205223 cookies,
0 commit comments