mirror of
https://gh-proxy.org/https://github.com/tiajinsha/JKVideo
synced 2026-07-07 23:18:38 +08:00
本项目已收到哔哩哔哩(bilibili)律师函,要求停止对 B 站 API 的调用及相关仿制行为。
为尊重知识产权及相关法律法规,本仓库即日起停止后续维护与更新,不再接受新的 Issue 和 Pull Request。 现有代码仅作学习参考保留,请勿将本项目用于任何商业或违法用途。 感谢所有支持过本项目的朋友。
This commit is contained in:
@@ -5,11 +5,13 @@ import { getSecure, setSecure, deleteSecure } from '../utils/secureStorage';
|
||||
|
||||
interface AuthState {
|
||||
sessdata: string | null;
|
||||
/** B 站 CSRF token(bili_jct cookie 值)。写操作(关注/点赞/投币 etc)必填 */
|
||||
biliJct: string | null;
|
||||
uid: string | null;
|
||||
username: string | null;
|
||||
face: string | null;
|
||||
isLoggedIn: boolean;
|
||||
login: (sessdata: string, uid: string, username?: string) => Promise<void>;
|
||||
login: (sessdata: string, uid: string, username?: string, biliJct?: string) => Promise<void>;
|
||||
logout: () => Promise<void>;
|
||||
restore: () => Promise<void>;
|
||||
setProfile: (face: string, username: string, uid: string) => void;
|
||||
@@ -17,16 +19,24 @@ interface AuthState {
|
||||
|
||||
export const useAuthStore = create<AuthState>((set) => ({
|
||||
sessdata: null,
|
||||
biliJct: null,
|
||||
uid: null,
|
||||
username: null,
|
||||
face: null,
|
||||
isLoggedIn: false,
|
||||
|
||||
login: async (sessdata, uid, username) => {
|
||||
login: async (sessdata, uid, username, biliJct) => {
|
||||
await setSecure('SESSDATA', sessdata);
|
||||
if (biliJct) await setSecure('bili_jct', biliJct);
|
||||
// Migrate: remove SESSDATA from AsyncStorage if it was there before
|
||||
await AsyncStorage.removeItem('SESSDATA').catch(() => { });
|
||||
set({ sessdata, uid: uid || null, username: username || null, isLoggedIn: true });
|
||||
set({
|
||||
sessdata,
|
||||
biliJct: biliJct ?? null,
|
||||
uid: uid || null,
|
||||
username: username || null,
|
||||
isLoggedIn: true,
|
||||
});
|
||||
getUserInfo().then(async (info) => {
|
||||
await AsyncStorage.multiSet([
|
||||
['UID', String(info.mid)],
|
||||
@@ -39,8 +49,9 @@ export const useAuthStore = create<AuthState>((set) => ({
|
||||
|
||||
logout: async () => {
|
||||
await deleteSecure('SESSDATA');
|
||||
await deleteSecure('bili_jct');
|
||||
await AsyncStorage.multiRemove(['UID', 'USERNAME', 'FACE']);
|
||||
set({ sessdata: null, uid: null, username: null, face: null, isLoggedIn: false });
|
||||
set({ sessdata: null, biliJct: null, uid: null, username: null, face: null, isLoggedIn: false });
|
||||
},
|
||||
|
||||
restore: async () => {
|
||||
@@ -54,8 +65,9 @@ export const useAuthStore = create<AuthState>((set) => ({
|
||||
await AsyncStorage.removeItem('SESSDATA');
|
||||
}
|
||||
}
|
||||
const biliJct = await getSecure('bili_jct');
|
||||
if (sessdata) {
|
||||
set({ sessdata, isLoggedIn: true });
|
||||
set({ sessdata, biliJct, isLoggedIn: true });
|
||||
try {
|
||||
const info = await getUserInfo();
|
||||
await AsyncStorage.setItem('FACE', info.face);
|
||||
|
||||
Reference in New Issue
Block a user