@@ -607,10 +607,17 @@ export class HankoAuth extends LitElement {
607607 // Configure cookie domain for cross-subdomain SSO
608608 const hostname = window . location . hostname ;
609609 const isLocalhost = hostname === "localhost" || hostname === "127.0.0.1" ;
610+
611+ // Extract base domain for cookie (e.g., "login.hotosm.org" -> ".hotosm.org")
612+ // Handles both production (.hotosm.org) and dev (.hotosm.test)
613+ const parts = hostname . split ( "." ) ;
614+ const baseDomain =
615+ parts . length >= 2 ? `.${ parts . slice ( - 2 ) . join ( "." ) } ` : hostname ;
616+
610617 const cookieOptions = isLocalhost
611618 ? { }
612619 : {
613- cookieDomain : ".hotosm.org" ,
620+ cookieDomain : baseDomain ,
614621 cookieName : "hanko" ,
615622 cookieSameSite : "lax" ,
616623 } ;
@@ -818,6 +825,12 @@ export class HankoAuth extends LitElement {
818825 }
819826
820827 private async checkOSMConnection ( ) {
828+ // Skip OSM check if not required
829+ if ( ! this . osmRequired ) {
830+ this . log ( "⏭️ OSM not required, skipping connection check" ) ;
831+ return ;
832+ }
833+
821834 if ( this . osmConnected ) {
822835 this . log ( "⏭️ Already connected to OSM, skipping check" ) ;
823836 return ;
@@ -1350,8 +1363,16 @@ export class HankoAuth extends LitElement {
13501363 this . log ( "📊 Current state:" , {
13511364 user : this . user ,
13521365 osmConnected : this . osmConnected ,
1366+ loading : this . loading ,
13531367 } ) ;
13541368
1369+ // If still loading, wait for session check to complete before acting
1370+ // The SDK may fire this event for old/stale sessions during init
1371+ if ( this . loading ) {
1372+ this . log ( "⏳ Still loading, ignoring session expired event during init" ) ;
1373+ return ;
1374+ }
1375+
13551376 // If we have an active user, the session is still valid
13561377 // The SDK may fire this event for old/stale sessions while a new session exists
13571378 if ( this . user ) {
@@ -1418,11 +1439,13 @@ export class HankoAuth extends LitElement {
14181439 this . log ( "🎯 Dropdown item selected:" , selectedValue ) ;
14191440
14201441 if ( selectedValue === "profile" ) {
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 ;
1442+ // Profile page: standalone apps have their own, others use central login service
1443+ // loginUrl already includes /app, hankoUrl doesn't
14241444 const returnTo = this . redirectAfterLogin || window . location . origin ;
1425- window . location . href = `${ baseUrl } /profile?return_to=${ encodeURIComponent ( returnTo ) } ` ;
1445+ const profileUrl = this . loginUrl
1446+ ? `${ this . loginUrl } /profile`
1447+ : `${ this . hankoUrl } /app/profile` ;
1448+ window . location . href = `${ profileUrl } ?return_to=${ encodeURIComponent ( returnTo ) } ` ;
14261449 } else if ( selectedValue === "connect-osm" ) {
14271450 // Smart return_to: if already on a login page, redirect to home instead
14281451 const currentPath = window . location . pathname ;
0 commit comments