diff --git a/frontend/index.html b/frontend/index.html index 750dc9a..6cecb6a 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -12,6 +12,13 @@ href="https://fonts.googleapis.com/css2?family=Cormorant+Garamond:wght@300;400&family=Noto+Serif+JP:wght@200;300&display=swap" rel="stylesheet" /> + diff --git a/frontend/src/components/admin/ui/me-auth-guard.ts b/frontend/src/components/admin/ui/me-auth-guard.ts new file mode 100644 index 0000000..c16a548 --- /dev/null +++ b/frontend/src/components/admin/ui/me-auth-guard.ts @@ -0,0 +1,76 @@ +import { consume } from '@lit/context' +import { css, html, LitElement, nothing } from 'lit' +import { customElement } from 'lit/decorators.js' +import { authContext } from '../../../contexts/auth-context.js' +import { RepositoryObserver } from '../../../controllers/RepositoryObserver.js' +import type { IAuthRepository } from '../../../domain/AuthRepository.js' + +/** + * A declarative component that protects its content based on authentication status. + */ +@customElement('me-auth-guard') +export class MeAuthGuard extends LitElement { + @consume({ context: authContext, subscribe: true }) + set authRepo(repo: IAuthRepository) { + if (this._authRepo === repo) return + this._authRepo = repo + this._observer?.disconnect() + if (repo) this._observer = new RepositoryObserver(this, repo) + } + get authRepo() { + return this._authRepo + } + private _authRepo!: IAuthRepository + private _observer?: RepositoryObserver + + connectedCallback() { + super.connectedCallback() + this.checkSession() + } + + private async checkSession() { + if (this.authRepo?.status === 'unknown') { + await this.authRepo.refreshSession() + } + } + + render() { + const status = this.authRepo?.status + + if (status === 'checking' || status === 'unknown') { + return html` +
認証状態を確認しています...
+