Skip to content

Commit 747cba9

Browse files
committed
feat: add userFullNameField and fill it if fullName field is empty
1 parent 3ab2c93 commit 747cba9

File tree

3 files changed

+30
-5
lines changed

3 files changed

+30
-5
lines changed

index.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import type { HttpExtra } from './types.js';
99
interface 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,

package-lock.json

Lines changed: 11 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,6 @@
5757
]
5858
},
5959
"dependencies": {
60-
"adminforth": "^2.4.0-next.221"
60+
"adminforth": "^2.13.0-next.43"
6161
}
6262
}

0 commit comments

Comments
 (0)