@@ -12,7 +12,7 @@ import { useEffect, useState, useCallback } from "react";
1212import React from "react" ;
1313import { handleFlowError } from "../util/handleFlowError" ;
1414import { Flow } from "../components/Flow" ;
15- import { kratos } from "../api/kratos" ;
15+ import { kratos , loginIdentifierFirst } from "../api/kratos" ;
1616import { FlowResponse } from "./consent" ;
1717import PageLayout from "../components/PageLayout" ;
1818import { replaceAuthLabel } from "../util/replaceAuthLabel" ;
@@ -35,7 +35,34 @@ type AppConfig = {
3535 oidc_webauthn_sequencing_enabled ?: boolean ;
3636} ;
3737
38- type IdentifierFirstResponse = { redirect_to : string } | LoginFlow ;
38+ const getTitleSuffix = ( reqName : string , reqDomain : string ) => {
39+ if ( reqName && reqDomain ) {
40+ return ` to ${ reqName } on ${ reqDomain } ` ;
41+ }
42+ if ( reqName ) {
43+ return ` to ${ reqName } ` ;
44+ }
45+ if ( reqDomain ) {
46+ return ` to ${ reqDomain } ` ;
47+ }
48+ return "" ;
49+ } ;
50+
51+ const resolveLoginTitle = (
52+ isIdentifierFirst : boolean ,
53+ isAuthCode : UiNode | undefined ,
54+ titleSuffix : string ,
55+ ) => {
56+ if ( isIdentifierFirst ) {
57+ return "Sign in" ;
58+ }
59+
60+ if ( isAuthCode ) {
61+ return "Verify your identity" ;
62+ }
63+
64+ return `Sign in${ titleSuffix } ` ;
65+ } ;
3966
4067const Login : NextPage = ( ) => {
4168 const [ flow , setFlow ] = useState < LoginFlow > ( ) ;
@@ -114,7 +141,7 @@ const Login: NextPage = () => {
114141 if ( login_challenge ) {
115142 return undefined ;
116143 }
117- return window . location . pathname . replace ( "login" , "manage_details" ) ;
144+ return window . location . pathname ;
118145 } ;
119146
120147 // Otherwise we initialize it
@@ -135,9 +162,18 @@ const Login: NextPage = () => {
135162 return ;
136163 }
137164
138- await router . replace ( `/ui/login?flow=${ data . id } ` , undefined , {
139- shallow : true ,
140- } ) ;
165+ await router . replace (
166+ {
167+ pathname : "/ui/login" ,
168+ query : {
169+ ...router . query ,
170+ flow : data . id ,
171+ } ,
172+ } ,
173+ undefined ,
174+ { shallow : true } ,
175+ ) ;
176+
141177 setFlow ( data ) ;
142178 } )
143179 . catch ( handleFlowError ( "login" , setFlow ) )
@@ -189,26 +225,7 @@ const Login: NextPage = () => {
189225 if ( method === "identifier_first" ) {
190226 const flowId = String ( flow ?. id ) ;
191227
192- return fetch (
193- `/api/kratos/self-service/login/id-first?flow=${ encodeURIComponent ( flowId ) } ` ,
194- {
195- method : "POST" ,
196- headers : {
197- "Content-Type" : "application/json" ,
198- } ,
199- body : JSON . stringify ( {
200- ...values ,
201- method,
202- flow : String ( flow ?. id ) ,
203- } ) ,
204- } ,
205- )
206- . then ( async ( res ) => {
207- if ( ! res . ok ) {
208- throw new Error ( await res . text ( ) ) ;
209- }
210- return ( await res . json ( ) ) as IdentifierFirstResponse ;
211- } )
228+ loginIdentifierFirst ( flowId , values , method , flow )
212229 . then ( ( data ) => {
213230 if ( "redirect_to" in data ) {
214231 window . location . href = data . redirect_to ;
@@ -272,29 +289,12 @@ const Login: NextPage = () => {
272289 } ,
273290 [ flow , router ] ,
274291 ) ;
275- const reqName = flow ?. oauth2_login_request ?. client ?. client_name ;
292+ const reqName = flow ?. oauth2_login_request ?. client ?. client_name ?? "" ;
276293 const reqDomain = flow ?. oauth2_login_request ?. client ?. client_uri
277294 ? new URL ( flow . oauth2_login_request . client . client_uri ) . hostname
278295 : "" ;
279-
280- const getTitleSuffix = ( ) => {
281- if ( reqName && reqDomain ) {
282- return ` to ${ reqName } on ${ reqDomain } ` ;
283- }
284- if ( reqName ) {
285- return ` to ${ reqName } ` ;
286- }
287- if ( reqDomain ) {
288- return ` to ${ reqDomain } ` ;
289- }
290- return "" ;
291- } ;
292-
293- const title = isIdentifierFirst
294- ? "Sign in"
295- : isAuthCode
296- ? "Verify your identity"
297- : `Sign in${ getTitleSuffix ( ) } ` ;
296+ const titleSuffix = getTitleSuffix ( reqName , reqDomain ) ;
297+ const title = resolveLoginTitle ( isIdentifierFirst , isAuthCode , titleSuffix ) ;
298298
299299 const filterFlow = ( flow : LoginFlow | undefined ) : LoginFlow => {
300300 if ( ! flow ) {
@@ -472,7 +472,8 @@ const Login: NextPage = () => {
472472 < >
473473 { isWebauthn && isSequencedLogin && (
474474 < p className = "u-text--muted" >
475- Additional authentication needed to get access { getTitleSuffix ( ) }
475+ Additional authentication needed to get access{ " " }
476+ { getTitleSuffix ( reqName , reqDomain ) }
476477 </ p >
477478 ) }
478479 { flow ? (
0 commit comments