diff --git a/src/api/HttpClient.ts b/src/api/HttpClient.ts index 92a24073..c235a506 100644 --- a/src/api/HttpClient.ts +++ b/src/api/HttpClient.ts @@ -6,7 +6,7 @@ import axios, { AxiosResponse, InternalAxiosRequestConfig, } from "axios" -import { PolimiToken, PoliNetworkToken, Tokens } from "./schemas" +import { PolimiToken, PoliNetworkToken, Tokens, tokensSchema } from "./schemas" import AsyncStorage from "@react-native-async-storage/async-storage" import { wait } from "utils/functions" import { Alert } from "react-native" @@ -432,8 +432,7 @@ export class HttpClient extends EventEmitter { async loadTokens() { const tokens = await AsyncStorage.getItem("api:tokens") if (tokens) { - // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment - const parsedTokens: Tokens = JSON.parse(tokens) + const parsedTokens: Tokens = tokensSchema.parse(JSON.parse(tokens)) console.log("Loaded tokens from local storage") this.polimiToken = parsedTokens.polimiToken this.poliNetworkToken = parsedTokens.poliNetworkToken diff --git a/src/pages/Login.tsx b/src/pages/Login.tsx index ef90ccbf..cf5b10c6 100644 --- a/src/pages/Login.tsx +++ b/src/pages/Login.tsx @@ -6,7 +6,11 @@ import WebView from "react-native-webview" import { usePalette } from "utils/colors" import { api } from "api" import { HttpClient } from "api/HttpClient" -import { PolimiToken, PoliNetworkToken } from "api/schemas" +import { + PolimiToken, + PoliNetworkToken, + poliNetworkTokenSchema, +} from "api/schemas" import { NavBar } from "components/NavBar" // TODO: HANDLE ERRORS, this will break as soon as something goes wrong @@ -132,8 +136,9 @@ export const Login: RootStackScreen<"Login"> = () => { if (url.startsWith(polinetworkTargetUrl)) { try { - // eslint-disable-next-line @typescript-eslint/no-unsafe-argument - setPoliNetworkToken(JSON.parse(data)) + setPoliNetworkToken( + poliNetworkTokenSchema.parse(JSON.parse(data)) + ) setCurrentURL(magicTokenUrl) } catch (e) { console.log("error while parsing!!")