File tree Expand file tree Collapse file tree 1 file changed +96
-1
lines changed
adminforth/documentation/docs/tutorial/07-Plugins Expand file tree Collapse file tree 1 file changed +96
-1
lines changed Original file line number Diff line number Diff line change @@ -389,4 +389,99 @@ This field will be automatically filled with the name that the provider returns,
389389
390390> Microsoft: returns fullName
391391
392- > Twitch: return only users display name
392+ > Twitch: return only users display name
393+
394+
395+ ## Automatically save users avatar
396+
397+ If you want to automatically upload users avatar from the provider, you can use userAvatarField prop.
398+
399+ Example:
400+
401+ First of all you'll need to create avatar field in your database:
402+
403+ Update schema prisma file:
404+
405+ ``` title="./schema.prisma"
406+
407+ model adminuser {
408+ id String @id
409+ email String @unique
410+ password_hash String
411+ role String
412+ created_at DateTime
413+ //diff-add
414+ avatar String
415+ }
416+
417+ ```
418+
419+ And make migration:
420+
421+ ``` bash
422+ npm run makemigration -- --name add-avatar-field ; npm run migrate:local
423+ ```
424+
425+ Then add this field to users resource:
426+
427+ ``` ts title="./resources/adminuser"
428+
429+ ...
430+
431+ columns : [
432+
433+ ...
434+ // diff-add
435+ {
436+ // diff-add
437+ name: " avatar" ,
438+ // diff-add
439+ type: AdminForthDataTypes .STRING ,
440+ // diff-add
441+ showIn: {
442+ // diff-add
443+ list: true ,
444+ // diff-add
445+ show: true
446+ // diff-add
447+ },
448+ // diff-add
449+ },
450+
451+ ...
452+
453+ ]
454+
455+ ...
456+
457+ ```
458+
459+ Then update your plugin setup:
460+
461+ ``` ts title="./resources/adminuser.ts"
462+
463+ ...
464+
465+
466+ plugins : [
467+
468+ ...
469+
470+ new OAuthPlugin ({
471+ userAvatarField: " avatar" ,
472+
473+ ...
474+
475+ })
476+
477+ ...
478+
479+ ]
480+
481+ ...
482+
483+ ```
484+
485+ Then you need to setup upload plugin for avatar field like it made here:
486+
487+ [ Using plugin for uploading avatar] ( https://adminforth.dev/docs/tutorial/Plugins/upload/#using-plugin-for-uploading-avatar )
You can’t perform that action at this time.
0 commit comments