diff --git a/apps/stage-web/src/pages/auth/login.vue b/apps/stage-web/src/pages/auth/login.vue index 695361182..82ad9ae75 100644 --- a/apps/stage-web/src/pages/auth/login.vue +++ b/apps/stage-web/src/pages/auth/login.vue @@ -1,46 +1,43 @@ diff --git a/packages/stage-layouts/src/components/Layouts/HeaderAvatar.vue b/packages/stage-layouts/src/components/Layouts/HeaderAvatar.vue index 566f27136..346be47ec 100644 --- a/packages/stage-layouts/src/components/Layouts/HeaderAvatar.vue +++ b/packages/stage-layouts/src/components/Layouts/HeaderAvatar.vue @@ -1,7 +1,7 @@ diff --git a/packages/stage-ui/src/components/auth/LoginDrawer.vue b/packages/stage-ui/src/components/auth/LoginDrawer.vue new file mode 100644 index 000000000..0c206339b --- /dev/null +++ b/packages/stage-ui/src/components/auth/LoginDrawer.vue @@ -0,0 +1,54 @@ + + + diff --git a/packages/stage-ui/src/components/auth/index.ts b/packages/stage-ui/src/components/auth/index.ts new file mode 100644 index 000000000..75d811dfe --- /dev/null +++ b/packages/stage-ui/src/components/auth/index.ts @@ -0,0 +1 @@ +export { default as LoginDrawer } from './LoginDrawer.vue' diff --git a/packages/stage-ui/src/components/index.ts b/packages/stage-ui/src/components/index.ts index c7f788f05..0ee6875ee 100644 --- a/packages/stage-ui/src/components/index.ts +++ b/packages/stage-ui/src/components/index.ts @@ -1,3 +1,4 @@ +export * from './auth' export * from './data-pane' export * from './gadgets' export * from './graphics' diff --git a/packages/stage-ui/src/composables/api.ts b/packages/stage-ui/src/composables/api.ts index 2703190ef..76611190b 100644 --- a/packages/stage-ui/src/composables/api.ts +++ b/packages/stage-ui/src/composables/api.ts @@ -3,15 +3,10 @@ import type { AppType } from '../../../../apps/server/src/app' import { hc } from 'hono/client' import { SERVER_URL } from '../libs/auth' -import { useAuthStore } from '../stores/auth' export const client = hc(SERVER_URL, { fetch: (input: RequestInfo | URL, init?: RequestInit) => { - const authStore = useAuthStore() const headers = new Headers(init?.headers) - if (authStore.authToken) { - headers.set('Authorization', `Bearer ${authStore.authToken}`) - } return fetch(input, { ...init, headers, diff --git a/packages/stage-ui/src/libs/auth.ts b/packages/stage-ui/src/libs/auth.ts index 1f513b0bb..208b6002b 100644 --- a/packages/stage-ui/src/libs/auth.ts +++ b/packages/stage-ui/src/libs/auth.ts @@ -4,29 +4,16 @@ import { useAuthStore } from '../stores/auth' export const SERVER_URL = import.meta.env.VITE_SERVER_URL || 'https://airi-api.moeru.ai' -const authStore = useAuthStore() - export const authClient = createAuthClient({ baseURL: SERVER_URL, - credentials: 'include', - fetchOptions: { - auth: { - type: 'Bearer', - token: () => authStore.authToken, - }, - onSuccess: (ctx) => { - const newToken = ctx.response.headers.get('set-auth-token') - if (newToken) { - authStore.authToken = newToken - } - }, - }, }) export async function fetchSession() { const { data } = await authClient.getSession() if (data) { + const authStore = useAuthStore() + authStore.user = data.user authStore.session = data.session return true @@ -42,7 +29,14 @@ export async function listSessions() { export async function signOut() { await authClient.signOut() + const authStore = useAuthStore() authStore.user = undefined authStore.session = undefined - authStore.authToken = '' +} + +export async function signIn(provider: 'google' | 'github') { + return await authClient.signIn.social({ + provider, + callbackURL: window.location.origin, + }) } diff --git a/packages/stage-ui/src/stores/auth.ts b/packages/stage-ui/src/stores/auth.ts index 81bdfae4b..8e6cc7dc6 100644 --- a/packages/stage-ui/src/stores/auth.ts +++ b/packages/stage-ui/src/stores/auth.ts @@ -1,21 +1,21 @@ import type { Session, User } from 'better-auth' -import { useLocalStorage } from '@vueuse/core' import { defineStore } from 'pinia' import { computed, ref } from 'vue' export const useAuthStore = defineStore('auth', () => { - const authToken = useLocalStorage('auth/token', '') const user = ref() const session = ref() const isAuthenticated = computed(() => !!user.value && !!session.value) + const isLoginOpen = ref(false) + // TODO: include fetchSession here for pulling and updating better-auth session with initialize(...) action return { - authToken, user, session, isAuthenticated, + isLoginOpen, } })