@@ -25,6 +25,7 @@ import {
2525 recompileScreenParams ,
2626 useScreenParams ,
2727} from "@/lib/hooks/screen-params" ;
28+ import { useEffect } from "react" ;
2829
2930type Scope = {
3031 id : string ;
@@ -90,7 +91,15 @@ export const AuthorizePage = () => {
9091 const isOidc = screenParams . login_for === "oidc" ;
9192 const compiledParams = recompileScreenParams ( screenParams ) ;
9293
93- const authorizeMutation = useMutation ( {
94+ // TODO: maybe a better way to do this
95+ const shouldAutoAuthorize =
96+ auth . authenticated &&
97+ isOidc &&
98+ screenParams . oidc_ticket !== undefined &&
99+ screenParams . oidc_scope !== undefined &&
100+ screenParams . oidc_prompt === "none" ;
101+
102+ const { mutate : authorizeMutate , isPending : authorizePending } = useMutation ( {
94103 mutationFn : ( ) => {
95104 return axios . post ( "/api/oidc/authorize-complete" , {
96105 ticket : screenParams . oidc_ticket ,
@@ -110,6 +119,12 @@ export const AuthorizePage = () => {
110119 } ,
111120 } ) ;
112121
122+ useEffect ( ( ) => {
123+ if ( shouldAutoAuthorize ) {
124+ authorizeMutate ( ) ;
125+ }
126+ } , [ shouldAutoAuthorize , authorizeMutate ] ) ;
127+
113128 if ( ! isOidc || ! screenParams . oidc_ticket || ! screenParams . oidc_scope ) {
114129 return (
115130 < Navigate
@@ -119,7 +134,7 @@ export const AuthorizePage = () => {
119134 ) ;
120135 }
121136
122- if ( ! auth . authenticated || screenParams . oidc_login ) {
137+ if ( ! auth . authenticated || screenParams . oidc_prompt === "login" ) {
123138 return < Navigate to = { `/login${ compiledParams } ` } replace /> ;
124139 }
125140
@@ -168,14 +183,15 @@ export const AuthorizePage = () => {
168183 ) }
169184 < CardFooter className = "flex flex-col items-stretch gap-3" >
170185 < Button
171- onClick = { ( ) => authorizeMutation . mutate ( ) }
172- loading = { authorizeMutation . isPending }
186+ onClick = { ( ) => authorizeMutate ( ) }
187+ loading = { authorizePending }
188+ disabled = { shouldAutoAuthorize }
173189 >
174190 { t ( "authorizeTitle" ) }
175191 </ Button >
176192 < Button
177193 onClick = { ( ) => navigate ( `/logout${ compiledParams } ` ) }
178- disabled = { authorizeMutation . isPending }
194+ disabled = { authorizePending || shouldAutoAuthorize }
179195 variant = "outline"
180196 >
181197 { t ( "cancelTitle" ) }
0 commit comments