Browse Source

feat:添加refresh token机制

zhangwl 1 month ago
parent
commit
96569961d7
1 changed files with 18 additions and 0 deletions
  1. 18 0
      chat-ai-ui-main/src/utils/auth.ts

+ 18 - 0
chat-ai-ui-main/src/utils/auth.ts

@@ -0,0 +1,18 @@
+import axios from 'axios';
+import { useUserStore } from '../stores/user';
+
+export async function refreshAuthToken(): Promise<string> {
+  const userStore = useUserStore();
+
+  if (!userStore.refreshToken) {
+    throw new Error('No refresh token available');
+  }
+
+  const { data } = await axios.post(
+    `${import.meta.env.VITE_API_URL}/users/refresh`,
+    null,
+    { params: { refresh_token: userStore.refreshToken } }
+  );
+
+  return data.access_token;
+}