Skip to content

Commit e13fecf

Browse files
committed
Fix profile URL path for standalone and non-standalone modes
1 parent 5ede563 commit e13fecf

File tree

7 files changed

+342
-310
lines changed

7 files changed

+342
-310
lines changed

auth-libs/web-component/dist/hanko-auth.esm.js

Lines changed: 299 additions & 290 deletions
Large diffs are not rendered by default.

auth-libs/web-component/dist/hanko-auth.iife.js

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

auth-libs/web-component/dist/hanko-auth.umd.js

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

auth-libs/web-component/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@hotosm/hanko-auth",
3-
"version": "0.3.2",
3+
"version": "0.3.4",
44
"description": "Web component for HOTOSM SSO authentication with Hanko and OSM integration",
55
"type": "module",
66
"main": "dist/hanko-auth.umd.js",

auth-libs/web-component/src/hanko-auth.ts

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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;

frontend/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"test:ui": "vitest --ui"
1313
},
1414
"dependencies": {
15-
"@hotosm/hanko-auth": "^0.3.3",
15+
"@hotosm/hanko-auth": "^0.3.4",
1616
"@teamhanko/hanko-elements": "^2.2.0",
1717
"react": "^19.2.0",
1818
"react-dom": "^19.2.0",

frontend/pnpm-lock.yaml

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)