-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+ PlayChat
+
+
+
+
+
+
+
-
-
+
+
diff --git a/frontend/src/stores/auth.ts b/frontend/src/stores/auth.ts
new file mode 100644
index 0000000..433103e
--- /dev/null
+++ b/frontend/src/stores/auth.ts
@@ -0,0 +1,51 @@
+import { defineStore } from 'pinia'
+import { ref } from 'vue'
+import { fetchAuthStatus, login as loginApi, logout as logoutApi } from '../api/client'
+
+export const useAuthStore = defineStore('auth', () => {
+ const required = ref(false)
+ const authenticated = ref(false)
+ const loading = ref(true)
+ const error = ref
(null)
+
+ async function checkStatus(): Promise {
+ loading.value = true
+ try {
+ const status = await fetchAuthStatus()
+ required.value = status.required
+ authenticated.value = status.authenticated
+ } catch (e) {
+ error.value = e instanceof Error ? e.message : 'エラーが発生しました'
+ } finally {
+ loading.value = false
+ }
+ }
+
+ async function login(password: string): Promise {
+ loading.value = true
+ error.value = null
+ try {
+ const status = await loginApi(password)
+ required.value = status.required
+ authenticated.value = status.authenticated
+ return true
+ } catch (e) {
+ authenticated.value = false
+ error.value = e instanceof Error ? e.message : 'エラーが発生しました'
+ return false
+ } finally {
+ loading.value = false
+ }
+ }
+
+ async function logout(): Promise {
+ await logoutApi().catch(() => {})
+ authenticated.value = false
+ }
+
+ function markUnauthenticated(): void {
+ authenticated.value = false
+ }
+
+ return { required, authenticated, loading, error, checkStatus, login, logout, markUnauthenticated }
+})