过渡版:本地验发token
This commit is contained in:
1 parent
fb71def840
commit
a5f0ec645d
14 files changed
+313
-220
No files matched your search
+18
-2
@@ -1,5 +1,4 @@
|
||||
|
||||
import { createApp } from 'vue'
|
||||
import { createApp } from 'vue'
|
||||
import './style.css'
|
||||
import App from './App.vue'
|
||||
import router from './router'
|
||||
@@ -9,6 +8,23 @@ import { config } from './config'
|
||||
// Set document title from config
|
||||
document.title = config.appTitle || 'AI工作台';
|
||||
|
||||
// Global 401 interceptor for API calls.
|
||||
const _rawFetch = window.fetch.bind(window);
|
||||
window.fetch = async (input: RequestInfo | URL, init?: RequestInit): Promise<Response> => {
|
||||
const res = await _rawFetch(input, init);
|
||||
try {
|
||||
const url = typeof input === 'string'
|
||||
? input
|
||||
: (input instanceof URL ? input.toString() : input.url);
|
||||
if (res.status === 401 && url.includes('/api/')) {
|
||||
window.dispatchEvent(new CustomEvent('hxops:unauthorized', { detail: { url, status: res.status } }));
|
||||
}
|
||||
} catch {
|
||||
// no-op
|
||||
}
|
||||
return res;
|
||||
};
|
||||
|
||||
createApp(App)
|
||||
.use(router)
|
||||
.use(i18n)
|
||||
|
||||
Reference in new issue
Block a user