Skip to content

Commit

Permalink
chore: Update runtimeConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
TNXG committed Sep 11, 2024
1 parent 499f4a9 commit 820864c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
5 changes: 4 additions & 1 deletion nuxt.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ export default defineNuxtConfig({
'nuxt-og-image'
],
runtimeConfig: {
...runtimeEnv
...runtimeEnv,
public: {
baseURL: process.env.NODE_ENV === 'development' ? 'http://localhost:3000' : appConfig.SiteConfig.SiteURL,
}
},
ui: {
notifications: {
Expand Down
11 changes: 7 additions & 4 deletions src/stores/verifyAuth.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { defineStore } from 'pinia';
import { useRuntimeConfig } from '#imports'; // 导入 runtime config

export const useAuthStore = defineStore('auth', {
state: () => ({
Expand All @@ -10,7 +11,7 @@ export const useAuthStore = defineStore('auth', {
async setToken(token) {
this.token = token;
const tokenCookie = useCookie('token');
tokenCookie.value = token; // 不设置 expires 选项
tokenCookie.value = token;
await this.verify();
},
clearToken() {
Expand All @@ -23,14 +24,15 @@ export const useAuthStore = defineStore('auth', {
userInfoCookie.value = null;
},
async verify() {
const RuntimeConfig = useRuntimeConfig();
try {
const data = await $fetch('/api/status/verify_auth', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${this.token}`
},
baseURL: process.env.BASE_URL || 'http://localhost:3000'
baseURL: RuntimeConfig.public.baseURL
});
if (data.code === "200") {
this.Status = { code: "200", message: "login_success", uid: data.uid, tokenCreated: data.tokenCreated, status: "success" };
Expand All @@ -56,6 +58,7 @@ export const useAuthStore = defineStore('auth', {
}
},
async get_userinfo() {
const RuntimeConfig = useRuntimeConfig();
const tokenCookie = useCookie('token');
const token = tokenCookie.value;

Expand All @@ -78,7 +81,7 @@ export const useAuthStore = defineStore('auth', {
'Content-Type': 'application/json',
'Authorization': `Bearer ${this.token}`
},
baseURL: process.env.BASE_URL || 'http://localhost:3000'
baseURL: RuntimeConfig.public.baseURL
});
if (data) {
this.userInfo = data;
Expand All @@ -94,4 +97,4 @@ export const useAuthStore = defineStore('auth', {
}
}
}
});
});

0 comments on commit 820864c

Please sign in to comment.