2026-07-13 12:45:06 +00:00
|
|
|
const AUTH_HOST = 'https://account.rokojori.com';
|
|
|
|
|
const APP_URL = 'https://roject.rokojori.com';
|
|
|
|
|
|
|
|
|
|
interface JwtUser {
|
|
|
|
|
userId: string;
|
|
|
|
|
email: string;
|
|
|
|
|
roles: string[];
|
|
|
|
|
products: string[];
|
2026-07-06 17:28:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class AppNav extends HTMLElement {
|
|
|
|
|
async connectedCallback(): Promise<void> {
|
2026-07-13 12:45:06 +00:00
|
|
|
const res = await fetch( '/api/auth/me' );
|
|
|
|
|
|
|
|
|
|
if ( !res.ok ) {
|
|
|
|
|
const loginHref = `${AUTH_HOST}/login.html?redirect=${encodeURIComponent( APP_URL )}`;
|
|
|
|
|
this.innerHTML = `
|
|
|
|
|
<nav>
|
2026-07-13 19:46:48 +00:00
|
|
|
<span class="nav-brand">Roject</span>
|
2026-07-13 12:45:06 +00:00
|
|
|
<div class="nav-links"></div>
|
|
|
|
|
<div class="nav-user">
|
|
|
|
|
<a href="${loginHref}">Log in</a>
|
|
|
|
|
</div>
|
|
|
|
|
</nav>
|
|
|
|
|
`;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const user = await res.json() as JwtUser;
|
|
|
|
|
const logoutHref = `${AUTH_HOST}/api/auth/logout?redirect=${encodeURIComponent( APP_URL )}`;
|
2026-07-06 17:28:59 +00:00
|
|
|
|
|
|
|
|
this.innerHTML = `
|
|
|
|
|
<nav>
|
2026-07-13 19:46:48 +00:00
|
|
|
<span class="nav-brand">Roject</span>
|
2026-07-06 17:28:59 +00:00
|
|
|
<div class="nav-links">
|
|
|
|
|
<a href="/dashboard.html">Dashboard</a>
|
|
|
|
|
<a href="/groups.html">Groups</a>
|
|
|
|
|
<a href="/projects.html">Projects</a>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="nav-user">
|
2026-07-13 12:45:06 +00:00
|
|
|
<span>${user.email}</span>
|
|
|
|
|
<a href="${logoutHref}">Log out</a>
|
2026-07-06 17:28:59 +00:00
|
|
|
</div>
|
|
|
|
|
</nav>
|
|
|
|
|
`;
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-07-13 12:45:06 +00:00
|
|
|
customElements.define( 'app-nav', AppNav );
|