@@ -1292,10 +1292,16 @@ export class HankoAuth extends LitElement {
12921292 "✅ Logout complete - component will re-render with updated state" ,
12931293 ) ;
12941294
1295- // Redirect after logout if configured
1295+ // Redirect after logout if configured (but not if already there)
12961296 if ( this . redirectAfterLogout ) {
1297- this . log ( "🔄 Redirecting after logout to:" , this . redirectAfterLogout ) ;
1298- window . location . href = this . redirectAfterLogout ;
1297+ const currentUrl = window . location . href . replace ( / \/ $ / , "" ) ;
1298+ const targetUrl = this . redirectAfterLogout . replace ( / \/ $ / , "" ) ;
1299+ if ( currentUrl !== targetUrl && ! currentUrl . startsWith ( targetUrl + "#" ) ) {
1300+ this . log ( "🔄 Redirecting after logout to:" , this . redirectAfterLogout ) ;
1301+ window . location . href = this . redirectAfterLogout ;
1302+ } else {
1303+ this . log ( "⏭️ Already on logout target, skipping redirect" ) ;
1304+ }
12991305 }
13001306 // Otherwise let Lit's reactivity handle the re-render
13011307 }
@@ -1384,13 +1390,19 @@ export class HankoAuth extends LitElement {
13841390
13851391 this . log ( "✅ Session cleanup complete" ) ;
13861392
1387- // Redirect after session expired if configured
1393+ // Redirect after session expired if configured (but not if already there)
13881394 if ( this . redirectAfterLogout ) {
1389- this . log (
1390- "🔄 Redirecting after session expired to:" ,
1391- this . redirectAfterLogout ,
1392- ) ;
1393- window . location . href = this . redirectAfterLogout ;
1395+ const currentUrl = window . location . href . replace ( / \/ $ / , "" ) ; // Remove trailing slash
1396+ const targetUrl = this . redirectAfterLogout . replace ( / \/ $ / , "" ) ;
1397+ if ( currentUrl !== targetUrl && ! currentUrl . startsWith ( targetUrl + "#" ) ) {
1398+ this . log (
1399+ "🔄 Redirecting after session expired to:" ,
1400+ this . redirectAfterLogout ,
1401+ ) ;
1402+ window . location . href = this . redirectAfterLogout ;
1403+ } else {
1404+ this . log ( "⏭️ Already on logout target, skipping redirect" ) ;
1405+ }
13941406 }
13951407 // Otherwise component will re-render and show login button
13961408 }
@@ -1406,11 +1418,11 @@ export class HankoAuth extends LitElement {
14061418 this . log ( "🎯 Dropdown item selected:" , selectedValue ) ;
14071419
14081420 if ( selectedValue === "profile" ) {
1409- // Profile page lives on the login site
1410- // Pass return URL so profile can navigate back to the app
1411- const baseUrl = this . hankoUrl ;
1421+ // Profile page lives on the login site (or standalone app's login page)
1422+ // Use loginUrl if set (standalone mode), otherwise hankoUrl
1423+ const baseUrl = this . loginUrl || this . hankoUrl ;
14121424 const returnTo = this . redirectAfterLogin || window . location . origin ;
1413- window . location . href = `${ baseUrl } /app/ profile?return_to=${ encodeURIComponent ( returnTo ) } ` ;
1425+ window . location . href = `${ baseUrl } /profile?return_to=${ encodeURIComponent ( returnTo ) } ` ;
14141426 } else if ( selectedValue === "connect-osm" ) {
14151427 // Smart return_to: if already on a login page, redirect to home instead
14161428 const currentPath = window . location . pathname ;
0 commit comments