Remove Convex module and its initialization from auth provider; update auth.json to reflect the change.
This commit is contained in:
@@ -1,43 +0,0 @@
|
||||
import { api } from "@kevisual/convex";
|
||||
import { ConvexClient, AuthTokenFetcher, ConvexHttpClient } from "convex/browser";
|
||||
const url = localStorage.getItem("CONVEX_URL") || 'https://convex.kevisual.cn'
|
||||
const client = new ConvexClient(url!);
|
||||
const httpClient = new ConvexHttpClient(url!);
|
||||
if (url !== 'https://convex.kevisual.cn') {
|
||||
console.warn("当前使用的Convex URL为:", url, "请确保这是你想要连接的Convex实例");
|
||||
}
|
||||
export const initConvex = async () => {
|
||||
const getToken = async () => {
|
||||
const token = localStorage.getItem("token");
|
||||
if (!token) {
|
||||
return null;
|
||||
}
|
||||
const res = await httpClient.action(api.token.create, { token: token! });
|
||||
if (res.code === 200) {
|
||||
return res.data.accessToken;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
const authTokenFetcher: AuthTokenFetcher = async ({ forceRefreshToken }: { forceRefreshToken: boolean }) => {
|
||||
// 无论是否强制刷新,都优先使用缓存(除非缓存无效)
|
||||
if (!forceRefreshToken) {
|
||||
const cachedToken = sessionStorage.getItem("convex_token");
|
||||
if (cachedToken) {
|
||||
return cachedToken;
|
||||
}
|
||||
}
|
||||
|
||||
// 没有缓存或强制刷新时,获取新 token
|
||||
const token = await getToken();
|
||||
if (token) {
|
||||
sessionStorage.setItem("convex_token", token);
|
||||
}
|
||||
return token;
|
||||
|
||||
}
|
||||
client.setAuth(authTokenFetcher, (isAuthenticated) => {
|
||||
console.log("Auth isAuthenticated:", isAuthenticated);
|
||||
});
|
||||
}
|
||||
|
||||
export { client, httpClient };
|
||||
@@ -5,7 +5,6 @@ import { LogIn, LockKeyhole } from "lucide-react"
|
||||
export { BaseHeader } from './modules/BaseHeader'
|
||||
import { useMemo } from 'react';
|
||||
import { useLocation, useNavigate } from '@tanstack/react-router';
|
||||
import { initConvex } from "@/modules/convex";
|
||||
|
||||
type Props = {
|
||||
children?: React.ReactNode,
|
||||
@@ -19,7 +18,6 @@ export const AuthProvider = ({ children, mustLogin }: Props) => {
|
||||
})));
|
||||
useEffect(() => {
|
||||
store.init()
|
||||
initConvex();
|
||||
}, [])
|
||||
const location = useLocation()
|
||||
const navigate = useNavigate();
|
||||
|
||||
Reference in New Issue
Block a user