api调整

This commit is contained in:
zhangkuo 2024-07-13 18:01:56 +08:00
parent 1ce9258c70
commit b86383e91c
3 changed files with 17 additions and 7 deletions

View File

@ -24,7 +24,6 @@ export function AuthPage() {
const goChat = () => navigate(Path.Chat);
const resetAccessCode = () => {
accessStore.update((access) => {
access.openaiApiKey = "";
access.accessCode = "";
});
};
@ -47,18 +46,29 @@ export function AuthPage() {
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
"Content-Type": "application/x-www-form-urlencoded",
},
body: formData.toString(),
credentials: "include", // 处理cookies
});
const data = await response.json();
if (data.status.code === 0 && data.result === true) {
// 登录成功逻辑
// 从响应中读取 session cookies
const cookies = response.headers.get("Set-Cookie");
if (cookies) {
console.log("Session cookies:", cookies);
accessStore.update((access) => {
access.accessCode = data.accessCode; // 如果需要从响应中获取 accessCode 的话
access.accessCode = cookies; // 将cookies赋值给access.accessCode
});
} else {
console.warn("No cookies found in the response.");
showToast(Locale.Login.LoginFail);
}
goChat(); // 导航到聊天页面或其他逻辑
} else {
// 登录失败

View File

@ -18,7 +18,7 @@ export const BAIDU_BASE_URL = "https://aip.baidubce.com";
export const BAIDU_OATUH_URL = `${BAIDU_BASE_URL}/oauth/2.0/token`;
export const BASE_URL = `https://buoucoding.com/ai`;
export const BASE_URL = `https://buoucoding.com/ai/api`;
export enum Login {
Register = "/register",

View File

@ -24,7 +24,7 @@ const cn = {
ConfirmPassword: "确认密码",
Login: "登录",
Register: "注册",
LoginFail: "登录失败,请检查用户名和密码",
LoginFail: "登录成功,但未找到会话信息。",
SystemFail: "请求失败,请重试",
ResisterSuc: "注册成功,请登录",
ResisterFail: "注册失败,请稍后重试",