check zipline version and error if lesser than v4.0.0

This commit is contained in:
Stef-00012 2025-02-26 19:15:43 +01:00
parent e4ad8f963e
commit c8533729d0
No known key found for this signature in database
GPG key ID: 28BE9A9E4EF0E6BF
3 changed files with 54 additions and 1 deletions

View file

@ -1,5 +1,6 @@
import { KeyboardAvoidingView } from "react-native-keyboard-controller";
import { isAuthenticated, login } from "@/functions/zipline/auth";
import { getVersion } from "@/functions/zipline/version";
import { useLoginAuth } from "@/hooks/useLoginAuth";
import TextInput from "@/components/TextInput";
import * as db from "@/functions/database";
@ -8,6 +9,7 @@ import Button from "@/components/Button";
import { useRouter } from "expo-router";
import { styles } from "@/styles/login";
import { useState } from "react";
import semver from "semver";
import React from "react";
export default function Login() {
@ -128,6 +130,18 @@ export default function Login() {
"There was an error during the login, make sure your token is valid and your server is running Zipline V4",
);
const versionData = await getVersion();
if (
typeof versionData === "string" ||
semver.lt(versionData.version, "4.0.0")
) {
await db.del("url");
await db.del("token");
return setError("You must use Zipline v4.0.0 or greater");
}
return router.replace("/");
}
@ -152,6 +166,18 @@ export default function Login() {
db.set("token", token);
const versionData = await getVersion();
if (
typeof versionData === "string" ||
semver.lt(versionData.version, "4.0.0")
) {
await db.del("url");
await db.del("token");
return setError("You must use Zipline v4.0.0 or greater");
}
return router.replace("/");
}}
text="Login"

View file

@ -1,7 +1,10 @@
import { isAuthenticated } from "@/functions/zipline/auth";
import { getVersion } from "@/functions/zipline/version";
import { useFocusEffect, useRouter } from "expo-router";
import type { APIUser } from "@/types/zipline";
import * as db from "@/functions/database";
import { roles } from "@/constants/auth";
import semver from "semver";
export const useAuth = (minimumRole: APIUser["role"] = "USER") => {
const router = useRouter();
@ -13,6 +16,18 @@ export const useAuth = (minimumRole: APIUser["role"] = "USER") => {
if (!authenticated) return router.replace("/login");
const versionData = await getVersion();
if (
typeof versionData === "string" ||
semver.lt(versionData.version, "4.0.0")
) {
await db.del("url");
await db.del("token");
return router.replace("/login");
}
const userPosition = roles[authenticated];
if (userPosition < minimumPosition) return router.replace("/");

View file

@ -1,5 +1,7 @@
import { isAuthenticated } from "@/functions/zipline/auth";
import { getVersion } from "@/functions/zipline/version";
import { useFocusEffect, useRouter } from "expo-router";
import semver from "semver";
export const useLoginAuth = () => {
const router = useRouter();
@ -17,6 +19,16 @@ export const useLoginAuth = () => {
async function loginAuth() {
const authenticated = await isAuthenticated();
if (authenticated) return router.replace("/");
if (!authenticated) return;
const versionData = await getVersion();
if (
typeof versionData === "string" ||
semver.lt(versionData.version, "4.0.0")
)
return;
router.replace("/");
}
};