e44d69a973
後端: - 新增 DivingOffer Model / DivingOfferController(列表+詳情 API,支援搜尋/篩選/分頁) - 修正 Google OAuth callback 改為 redirect 至前端(SocialAuthController) - 新增 config/cors.php 允許前端 origin - .gitignore 新增 frontend/ 排除規則 前端(frontend/): - Vue 3 + Vite + Tailwind CSS + Pinia + Vue Router - 頁面:首頁、課程列表、課程詳情、登入、註冊、個人資料、OAuth callback - 整合至 Docker(multi-stage build,nginx 靜態服務於 port 5173) Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
39 lines
987 B
JavaScript
39 lines
987 B
JavaScript
import { defineStore } from 'pinia'
|
|
import { ref, computed } from 'vue'
|
|
import api from '../api/axios'
|
|
|
|
export const useAuthStore = defineStore('auth', () => {
|
|
const user = ref(null)
|
|
const token = ref(null)
|
|
|
|
const isLoggedIn = computed(() => !!token.value)
|
|
|
|
function init() {
|
|
const saved = localStorage.getItem('token')
|
|
const savedUser = localStorage.getItem('user')
|
|
if (saved) {
|
|
token.value = saved
|
|
user.value = savedUser ? JSON.parse(savedUser) : null
|
|
}
|
|
}
|
|
|
|
function setAuth(userData, tokenValue) {
|
|
user.value = userData
|
|
token.value = tokenValue
|
|
localStorage.setItem('token', tokenValue)
|
|
localStorage.setItem('user', JSON.stringify(userData))
|
|
}
|
|
|
|
async function logout() {
|
|
try {
|
|
await api.post('/member/logout')
|
|
} catch {}
|
|
user.value = null
|
|
token.value = null
|
|
localStorage.removeItem('token')
|
|
localStorage.removeItem('user')
|
|
}
|
|
|
|
return { user, token, isLoggedIn, init, setAuth, logout }
|
|
})
|