Skip to content

Commit 070bdf5

Browse files
authored
Merge pull request #23 from Augigauki/main
Feat: update user info during signin flow
2 parents 17a13c8 + 222f676 commit 070bdf5

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/index.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ import { createElement } from 'react'
2222

2323
export { OAuthButton, oAuthPluginOptions }
2424

25-
interface User {}
25+
interface User {
26+
id: string | number
27+
}
2628

2729
const log = debug('plugin:oauth')
2830

@@ -173,6 +175,14 @@ function oAuthPluginServer(
173175

174176
if (users.docs && users.docs.length) {
175177
user = users.docs[0]
178+
if (options.updateOnLogin) {
179+
user = await payload.update({
180+
collection: collectionSlug,
181+
id: user.id,
182+
data: info,
183+
showHiddenFields: true,
184+
})
185+
}
176186
user.collection = collectionSlug
177187
user._strategy = strategyName
178188
} else {

src/types.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ export interface oAuthPluginOptions extends StrategyOptions {
7171
* @default /admin
7272
*/
7373
successRedirect?: string
74+
75+
/**
76+
* Boolean to allow updating users on login
77+
* @default false
78+
*/
79+
updateOnLogin?: boolean
7480
}
7581

7682
export type ButtonProps = {

0 commit comments

Comments
 (0)