mirror of
https://github.com/stackblitz/bolt.new
synced 2025-06-26 18:17:50 +00:00
feat: 更新了部分依赖包的开发状态标记
This commit is contained in:
17
app/utils/api.ts
Normal file
17
app/utils/api.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
export async function authenticatedFetch(url: string, options: RequestInit = {}) {
|
||||
const token = localStorage.getItem('token');
|
||||
const headers = {
|
||||
...options.headers,
|
||||
'Authorization': `Bearer ${token}`,
|
||||
};
|
||||
|
||||
const response = await fetch(url, { ...options, headers });
|
||||
|
||||
if (response.status === 401) {
|
||||
// Token is invalid or expired
|
||||
localStorage.removeItem('token');
|
||||
window.location.href = '/login';
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
Reference in New Issue
Block a user