11import styles from "./authentication.module.css" ;
22
3- import { useEffect , useState } from "react" ;
3+ import { useEffect , useRef , useState } from "react" ;
44import { SiGoogle , SiOpenid } from "@icons-pack/react-simple-icons" ;
55import { KeyRoundIcon } from "lucide-react" ;
66
@@ -105,7 +105,7 @@ const ProviderSettings = ({
105105 < SettingsSwitch
106106 name = "allowUserCreation"
107107 label = "Allow new users"
108- description = "Create an account after a user's first verified sign-in ."
108+ description = "Create an account when a user signs in successfully for the first time ."
109109 checked = { settings . allowUserCreation }
110110 onCheckedChange = { ( allowUserCreation ) => update ( "allowUserCreation" , allowUserCreation ) }
111111 />
@@ -135,7 +135,10 @@ const ProviderSettings = ({
135135 />
136136 </ SettingsField >
137137 ) }
138- < SettingsField label = "Client ID" name = "clientId" >
138+ < SettingsField
139+ label = { settings . provider === "microsoft" ? "Application (client) ID" : "Client ID" }
140+ name = "clientId"
141+ >
139142 < input
140143 name = "clientId"
141144 value = { settings . clientId }
@@ -192,7 +195,7 @@ const ProviderSettings = ({
192195 ) }
193196 { settings . provider === "microsoft" && (
194197 < SettingsField
195- label = "Tenant ID"
198+ label = "Directory (tenant) ID"
196199 description = "The directory ID for the Microsoft Entra tenant that can sign in."
197200 name = "tenantId"
198201 >
@@ -214,6 +217,9 @@ export const AuthenticationSettingsPage = () => {
214217 const [ savedSettings , setSavedSettings ] = useState < ExternalAuthSettings > ( ) ;
215218 const [ error , setError ] = useState < string > ( ) ;
216219 const [ clientSecret , setClientSecret ] = useState ( "" ) ;
220+ const providerDrafts = useRef <
221+ Partial < Record < ExternalAuthProvider , { settings : ExternalAuthSettings ; clientSecret : string } > >
222+ > ( { } ) ;
217223
218224 useEffect ( ( ) => {
219225 api [ "/api/dashboard/admin/auth" ]
@@ -222,6 +228,7 @@ export const AuthenticationSettingsPage = () => {
222228 . then ( ( settings ) => {
223229 setSettings ( settings ) ;
224230 setSavedSettings ( settings ) ;
231+ providerDrafts . current [ settings . provider ] = { settings, clientSecret : "" } ;
225232 } )
226233 . catch ( ( error ) => setError ( errorMessage ( error ) ) ) ;
227234 } , [ ] ) ;
@@ -232,6 +239,7 @@ export const AuthenticationSettingsPage = () => {
232239 const update = < K extends keyof ExternalAuthSettings > ( key : K , value : ExternalAuthSettings [ K ] ) =>
233240 setSettings ( { ...settings , [ key ] : value } ) ;
234241 const selectProvider = ( provider : ExternalAuthProvider | "internal" ) => {
242+ providerDrafts . current [ settings . provider ] = { settings, clientSecret } ;
235243 if ( provider === "internal" ) {
236244 setSettings ( { ...settings , enabled : false } ) ;
237245 return ;
@@ -240,17 +248,25 @@ export const AuthenticationSettingsPage = () => {
240248 setSettings ( { ...settings , enabled : true } ) ;
241249 return ;
242250 }
243- setClientSecret ( "" ) ;
251+
252+ const draft = providerDrafts . current [ provider ] ;
253+ if ( draft ) {
254+ setSettings ( { ...draft . settings , enabled : true } ) ;
255+ setClientSecret ( draft . clientSecret ) ;
256+ return ;
257+ }
258+
244259 setSettings ( {
245260 ...settings ,
246261 enabled : true ,
247262 provider,
248- displayName : provider === "oidc" ? "OpenID Connect" : settings . displayName ,
263+ displayName : providers . find ( ( item ) => item . value === provider ) ?. label ?? settings . displayName ,
249264 clientId : "" ,
250265 issuerUrl : null ,
251266 allowedDomain : null ,
252267 tenantId : null ,
253268 } ) ;
269+ setClientSecret ( "" ) ;
254270 } ;
255271
256272 const save = ( ) => {
@@ -281,6 +297,7 @@ export const AuthenticationSettingsPage = () => {
281297 setSettings ( next ) ;
282298 setSavedSettings ( next ) ;
283299 setClientSecret ( "" ) ;
300+ providerDrafts . current [ next . provider ] = { settings : next , clientSecret : "" } ;
284301 createToast ( "Authentication settings updated" , "success" ) ;
285302 } )
286303 . catch ( ( error ) => {
@@ -319,7 +336,11 @@ export const AuthenticationSettingsPage = () => {
319336 { settings . enabled && (
320337 < div className = { styles . callbackSection } >
321338 < h2 > Callback URL</ h2 >
322- < p > Add this exact URL to the provider application's allowed redirect URLs.</ p >
339+ < p >
340+ { settings . provider === "microsoft"
341+ ? "In Microsoft Entra ID, select the Web platform and add this exact URL as a redirect URI."
342+ : "Add this exact URL to the provider application's allowed redirect URLs." }
343+ </ p >
323344 < CopyableValue value = { settings . callbackUrl } label = "Callback URL" />
324345 </ div >
325346 ) }
0 commit comments