@@ -18,7 +18,8 @@ type $LoginData = z.infer<typeof $LoginData>;
1818const $LoginData = z . object ( {
1919 apiBaseUrl : z . url ( ) ,
2020 username : z . string ( ) . min ( 1 ) ,
21- password : z . string ( ) . min ( 1 )
21+ password : z . string ( ) . min ( 1 ) ,
22+ legacyLogin : z . boolean ( )
2223} ) ;
2324
2425export type LoginDialogProps = {
@@ -80,20 +81,24 @@ export const LoginDialog = ({ isOpen, setIsOpen }: LoginDialogProps) => {
8081 } ) ;
8182 } ;
8283
83- const handleSubmit = async ( { apiBaseUrl, ...credentials } : $LoginData ) => {
84+ const handleSubmit = async ( { apiBaseUrl, legacyLogin , ...credentials } : $LoginData ) => {
8485 updateSettings ( { apiBaseUrl } ) ;
8586 const adminTokenResult = await getAdminToken ( credentials ) ;
8687 if ( adminTokenResult . isErr ( ) ) {
8788 addNotification ( { type : 'error' , title : 'Login Failed' , message : adminTokenResult . error } ) ;
8889 return ;
8990 }
90- const limitedTokenResult = await getLimitedToken ( adminTokenResult . value . accessToken ) ;
91- if ( limitedTokenResult . isErr ( ) ) {
92- addNotification ( { type : 'error' , title : 'Failed to Get Limited Token' , message : limitedTokenResult . error } ) ;
93- return ;
94- }
9591
96- login ( limitedTokenResult . value . accessToken ) ;
92+ if ( legacyLogin ) {
93+ login ( adminTokenResult . value . accessToken ) ;
94+ } else {
95+ const limitedTokenResult = await getLimitedToken ( adminTokenResult . value . accessToken ) ;
96+ if ( limitedTokenResult . isErr ( ) ) {
97+ addNotification ( { type : 'error' , title : 'Failed to Get Limited Token' , message : limitedTokenResult . error } ) ;
98+ return ;
99+ }
100+ login ( limitedTokenResult . value . accessToken ) ;
101+ }
97102
98103 addNotification ( { type : 'success' } ) ;
99104 } ;
@@ -137,6 +142,20 @@ export const LoginDialog = ({ isOpen, setIsOpen }: LoginDialogProps) => {
137142 placeholder : 'e.g., https://demo.opendatacapture.org/api' ,
138143 label : 'API Base URL' ,
139144 variant : 'input'
145+ } ,
146+ legacyLogin : {
147+ description : [
148+ "Use the user's full access token instead of a granular access token." ,
149+ 'Note that this can introduce security risks and should not be used on shared machines.' ,
150+ 'It is required only for ODC versions prior to v1.12.0.'
151+ ] . join ( '' ) ,
152+ kind : 'boolean' ,
153+ label : 'Legacy Login Mode' ,
154+ variant : 'radio' ,
155+ options : {
156+ false : 'No (Recommended)' ,
157+ true : 'Yes'
158+ }
140159 }
141160 }
142161 } ,
@@ -156,7 +175,7 @@ export const LoginDialog = ({ isOpen, setIsOpen }: LoginDialogProps) => {
156175 }
157176 }
158177 ] }
159- initialValues = { { apiBaseUrl } }
178+ initialValues = { { apiBaseUrl, legacyLogin : false } }
160179 validationSchema = { $LoginData }
161180 onSubmit = { async ( data ) => {
162181 await handleSubmit ( data ) ;
0 commit comments