Skip to content

Commit 24f53ba

Browse files
committed
docs: update AdminUserExternalIdentity model and resource configuration for improved handling of external identities
1 parent c3785fb commit 24f53ba

1 file changed

Lines changed: 31 additions & 24 deletions

File tree

  • adminforth/documentation/docs/tutorial/08-Plugins

adminforth/documentation/docs/tutorial/08-Plugins/11-oauth.md

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ model AdminUserExternalIdentity {
5858
avatarUrl String?
5959
meta Json?
6060
createdAt DateTime @default(now())
61-
updatedAt DateTime @updatedAt
6261
6362
@@unique([provider, subject])
6463
@@index([adminUserId])
@@ -73,14 +72,21 @@ pnpm makemigration --name add-admin-user-external-identities ; pnpm migrate:loca
7372

7473
```ts title="./resources/adminUserExternalIdentities.ts"
7574
import { AdminForthDataTypes, type AdminForthResourceInput } from 'adminforth';
75+
import { randomUUID } from 'crypto';
7676

7777
export default {
78-
dataSource: 'sqlite',
78+
dataSource: 'maindb',
7979
table: 'AdminUserExternalIdentity',
8080
resourceId: 'admin_user_external_identities',
8181
label: 'Admin User External Identities',
8282
columns: [
83-
{ name: 'id', type: AdminForthDataTypes.STRING, primaryKey: true },
83+
{
84+
name: 'id',
85+
type: AdminForthDataTypes.STRING,
86+
primaryKey: true,
87+
fillOnCreate: () => randomUUID(),
88+
showIn: { create: false, edit: false },
89+
},
8490
{ name: 'adminUserId', type: AdminForthDataTypes.STRING, required: true },
8591
{ name: 'provider', type: AdminForthDataTypes.STRING, required: true },
8692
{ name: 'subject', type: AdminForthDataTypes.STRING, required: true },
@@ -90,6 +96,12 @@ export default {
9096
{ name: 'fullName', type: AdminForthDataTypes.STRING },
9197
{ name: 'avatarUrl', type: AdminForthDataTypes.STRING },
9298
{ name: 'meta', type: AdminForthDataTypes.JSON },
99+
{
100+
name: 'createdAt',
101+
type: AdminForthDataTypes.DATETIME,
102+
fillOnCreate: () => new Date().toISOString(),
103+
showIn: { create: false, edit: false },
104+
},
93105
],
94106
} satisfies AdminForthResourceInput;
95107
```
@@ -308,28 +320,23 @@ TELEGRAM_CLIENT_SECRET=your_telegram_client_secret
308320

309321
Add the adapter to your plugin configuration:
310322

311-
```ts
312-
import OAuthPlugin from '@adminforth/oauth';
313-
import TelegramOauthAdapter from '@adminforth/oauth-adapter-telegram';
323+
```typescript title="./resources/adminuser.ts"
324+
import AdminForthAdapterTelegramOauth2 from '@adminforth/oauth-adapter-telegram';
314325

315-
new OAuthPlugin({
316-
emailField: 'email',
317-
externalIdentityResource: {
318-
resourceId: 'admin_user_external_identities',
319-
phoneField: 'phone',
320-
fullNameField: 'fullName',
321-
avatarUrlField: 'avatarUrl',
322-
metaField: 'meta',
323-
},
324-
adapters: [
325-
new TelegramOauthAdapter({
326-
clientID: process.env.TELEGRAM_CLIENT_ID as string,
327-
clientSecret: process.env.TELEGRAM_CLIENT_SECRET as string,
328-
redirectUri: 'https://example.com/oauth/callback',
329-
scopes: ['openid', 'profile', 'phone'],
330-
}),
331-
],
332-
});
326+
// ... existing resource configuration ...
327+
plugins: [
328+
new OAuthPlugin({
329+
adapters: [
330+
...
331+
new TelegramOauthAdapter({
332+
clientID: process.env.TELEGRAM_CLIENT_ID as string,
333+
clientSecret: process.env.TELEGRAM_CLIENT_SECRET as string,
334+
redirectUri: 'https://example.com/oauth/callback',
335+
scopes: ['openid', 'profile', 'phone'],
336+
}),
337+
],
338+
}),
339+
]
333340
```
334341

335342
Register the same `redirectUri` in BotFather under **Login Widget → Redirect URI**.

0 commit comments

Comments
 (0)