@@ -18,6 +18,7 @@ import { TextField } from 'payload/types'
1818
1919import OAuthButton from './OAuthButton'
2020import type { oAuthPluginOptions } from './types'
21+ import { createElement } from 'react'
2122
2223export { OAuthButton , oAuthPluginOptions }
2324
@@ -94,20 +95,25 @@ function oAuthPluginClient(
9495 incoming : Config ,
9596 options : oAuthPluginOptions
9697) : Config {
97- const button : React . ComponentType < any > =
98- options . components ?. Button || OAuthButton
99- return {
100- ...incoming ,
101- admin : {
102- ...incoming . admin ,
103- components : {
104- ...incoming . admin ?. components ,
105- beforeLogin : ( incoming . admin ?. components ?. beforeLogin || [ ] ) . concat (
106- button
107- ) ,
108- } ,
109- } ,
110- }
98+ const button = options . components ?. Button ?? OAuthButton
99+ return button
100+ ? {
101+ ...incoming ,
102+ admin : {
103+ ...incoming . admin ,
104+ components : {
105+ ...incoming . admin ?. components ,
106+ beforeLogin : ( incoming . admin ?. components ?. beforeLogin || [ ] ) . concat (
107+ ( ) =>
108+ createElement ( button , {
109+ authorizePath : options . authorizePath || '/oauth2/authorize' ,
110+ buttonLabel : options . buttonLabel || `Sign in with oAuth` ,
111+ } )
112+ ) ,
113+ } ,
114+ } ,
115+ }
116+ : incoming
111117}
112118
113119function oAuthPluginServer (
@@ -123,7 +129,7 @@ function oAuthPluginServer(
123129 const collectionSlug = ( options . userCollection ?. slug as 'users' ) || 'users'
124130 const sub = options . subField ?. name || 'sub'
125131 const oAuthStrategyCount = ( incoming . custom ?. oAuthStrategyCount || 0 ) + 1
126- const strategyName = `oauth2-${ incoming . custom ?. oAuthStrategyCount } `
132+ const strategyName = `oauth2-${ oAuthStrategyCount } `
127133
128134 if ( options . clientID ) {
129135 // Validate paths, they must be unique
0 commit comments