4 Commits

Author SHA1 Message Date
zimplexing
c514a6d03e chore: update version to 1.2.1 in package.json 2025-07-16 22:06:28 +08:00
zimplexing
f6baa0523c feat: enhance authentication flow by adding server configuration check and login handling in authStore 2025-07-16 22:06:04 +08:00
zimplexing
9540aaa3b9 chore: update version to 1.2.0 in package.json 2025-07-16 21:31:21 +08:00
Xin
8a1c26991b Merge pull request #38 from zimplexing/v1.2.0
Adapt moontv api
2025-07-16 21:29:51 +08:00
3 changed files with 19 additions and 8 deletions

View File

@@ -2,7 +2,7 @@
"name": "OrionTV", "name": "OrionTV",
"private": true, "private": true,
"main": "expo-router/entry", "main": "expo-router/entry",
"version": "1.1.2", "version": "1.2.1",
"scripts": { "scripts": {
"start": "EXPO_USE_METRO_WORKSPACE_ROOT=1 expo start", "start": "EXPO_USE_METRO_WORKSPACE_ROOT=1 expo start",
"start-tv": "EXPO_TV=1 EXPO_USE_METRO_WORKSPACE_ROOT=1 expo start", "start-tv": "EXPO_TV=1 EXPO_USE_METRO_WORKSPACE_ROOT=1 expo start",

View File

@@ -121,7 +121,7 @@ export class API {
} }
async getFavorites(key?: string): Promise<Record<string, Favorite> | Favorite | null> { async getFavorites(key?: string): Promise<Record<string, Favorite> | Favorite | null> {
const url = key ? `/api/favorites?key=${key}` : "/api/favorites"; const url = key ? `/api/favorites?key=${encodeURIComponent(key)}` : "/api/favorites";
const response = await this._fetch(url); const response = await this._fetch(url);
return response.json(); return response.json();
} }
@@ -136,7 +136,7 @@ export class API {
} }
async deleteFavorite(key?: string): Promise<{ success: boolean }> { async deleteFavorite(key?: string): Promise<{ success: boolean }> {
const url = key ? `/api/favorites?key=${key}` : "/api/favorites"; const url = key ? `/api/favorites?key=${encodeURIComponent(key)}` : "/api/favorites";
const response = await this._fetch(url, { method: "DELETE" }); const response = await this._fetch(url, { method: "DELETE" });
return response.json(); return response.json();
} }
@@ -156,7 +156,7 @@ export class API {
} }
async deletePlayRecord(key?: string): Promise<{ success: boolean }> { async deletePlayRecord(key?: string): Promise<{ success: boolean }> {
const url = key ? `/api/playrecords?key=${key}` : "/api/playrecords"; const url = key ? `/api/playrecords?key=${encodeURIComponent(key)}` : "/api/playrecords";
const response = await this._fetch(url, { method: "DELETE" }); const response = await this._fetch(url, { method: "DELETE" });
return response.json(); return response.json();
} }

View File

@@ -1,6 +1,7 @@
import { create } from "zustand"; import { create } from "zustand";
import Cookies from "@react-native-cookies/cookies"; import Cookies from "@react-native-cookies/cookies";
import { api } from "@/services/api"; import { api } from "@/services/api";
import { useSettingsStore } from "./settingsStore";
interface AuthState { interface AuthState {
isLoggedIn: boolean; isLoggedIn: boolean;
@@ -22,11 +23,21 @@ const useAuthStore = create<AuthState>((set) => ({
return; return;
} }
try { try {
const serverConfig = useSettingsStore.getState().serverConfig;
const cookies = await Cookies.get(api.baseURL); const cookies = await Cookies.get(api.baseURL);
const isLoggedIn = cookies && !!cookies.auth; if (serverConfig && serverConfig.StorageType === "localstorage" && !cookies.auth) {
set({ isLoggedIn }); const loginResult = await api.login().catch(() => {
if (!isLoggedIn) { set({ isLoggedIn: false, isLoginModalVisible: true });
set({ isLoginModalVisible: true }); });
if (loginResult && loginResult.ok) {
set({ isLoggedIn: true });
}
} else {
const isLoggedIn = cookies && !!cookies.auth;
set({ isLoggedIn });
if (!isLoggedIn) {
set({ isLoginModalVisible: true });
}
} }
} catch (error) { } catch (error) {
console.info("Failed to check login status:", error); console.info("Failed to check login status:", error);