diff --git a/src/App.vue b/src/App.vue
index 6840c91..c15164e 100644
--- a/src/App.vue
+++ b/src/App.vue
@@ -1,19 +1,51 @@
@@ -24,13 +56,50 @@ onMounted(() => {
EasyTierMC Uptime
+
+
+
+
+
+
+
![]()
+
+
+
{{ userInfo.username || '用户' }}
+
+
+
+ -
+
+ 管理控制台
+
+
+
+
+
+
+
diff --git a/src/router/index.ts b/src/router/index.ts
index e8738af..5733cf4 100644
--- a/src/router/index.ts
+++ b/src/router/index.ts
@@ -1,6 +1,5 @@
import { createRouter, createWebHistory } from 'vue-router'
import HomeView from '../views/HomeView.vue'
-
const router = createRouter({
history: createWebHistory(import.meta.env.BASE_URL),
routes: [
diff --git a/src/utils/request/api.ts b/src/utils/request/api.ts
index e26a758..8aa91d2 100644
--- a/src/utils/request/api.ts
+++ b/src/utils/request/api.ts
@@ -6,6 +6,23 @@ export interface HealthResponse {
[key: string]: any
}
+interface IMe{
+ username:string,
+ avatar:string,
+}
+
+interface ILogin{
+ info:{
+ login:string,
+ avatar_url:string,
+ }
+}
+
+export async function login(code:string){
+ const res = await Api.post('http://localhost:3000/auth/oauth?code='+code);
+ return res as unknown as ILogin
+}
+
export function getHealth() {
const path = import.meta.env.VITE_HEALTH_PATH || '/health'
return Api.get(path)
@@ -20,25 +37,34 @@ export interface LoginResponse {
[key: string]: any
}
-export async function login(username: string, password: string) {
- const res = (await Api.post('/auth/login', { username, password })) as unknown as LoginResponse
- const token = (res as any)?.data.token
- if (token) {
- localStorage.setItem('auth_token', token)
- }
- return res
-}
+// export async function login(username: string, password: string) {
+// const res = (await Api.post('/auth/login', { username, password })) as unknown as LoginResponse
+// const token = (res as any)?.data.token
+// if (token) {
+// localStorage.setItem('auth_token', token)
+// }
+// return res
+// }
export function logout() {
- localStorage.removeItem('auth_token')
+ sessionStorage.removeItem('me')
+ cookieStore.delete('auth_token')
}
-export function isAuthenticated() {
- return !!localStorage.getItem('auth_token')
+export async function isAuthenticated() {
+ const s = sessionStorage.getItem('me');
+ const c = await cookieStore.get('auth_token')
+ return !!(s&&c)
+ //return true
}
export function getMe() {
- return (Api.get('/auth/me') as Promise)
+ let result:IMe|undefined = undefined;
+ const localme = sessionStorage.getItem('me')
+ if(localme){
+ result = JSON.parse(localme)
+ }
+ return /*(Api.get('/auth/me') as Promise)*/result;
}
// Admin list (requires admin role)
diff --git a/src/utils/request/index.ts b/src/utils/request/index.ts
index be852f9..75a466d 100644
--- a/src/utils/request/index.ts
+++ b/src/utils/request/index.ts
@@ -5,13 +5,13 @@ const Api = axios.create({
headers: {
'Content-Type': 'application/json'
},
- withCredentials: false,
+ withCredentials: true,
timeout: 30000
})
Api.interceptors.request.use(
(config) => {
- const token = localStorage.getItem('auth_token')
+ const token = cookieStore.get('auth_token')
if (token) {
config.headers = config.headers || {}
config.headers.Authorization = `Bearer ${token}`
diff --git a/src/views/LoginView.vue b/src/views/LoginView.vue
index d00034f..a4757a6 100644
--- a/src/views/LoginView.vue
+++ b/src/views/LoginView.vue
@@ -1,13 +1,35 @@