Skip to content

Commit 84491e5

Browse files
committed
token schema parse
1 parent ed15a27 commit 84491e5

2 files changed

Lines changed: 10 additions & 6 deletions

File tree

src/api/HttpClient.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import axios, {
66
AxiosResponse,
77
InternalAxiosRequestConfig,
88
} from "axios"
9-
import { PolimiToken, PoliNetworkToken, Tokens } from "./schemas"
9+
import { PolimiToken, PoliNetworkToken, Tokens, tokensSchema } from "./schemas"
1010
import AsyncStorage from "@react-native-async-storage/async-storage"
1111
import { wait } from "utils/functions"
1212
import { Alert } from "react-native"
@@ -432,8 +432,7 @@ export class HttpClient extends EventEmitter {
432432
async loadTokens() {
433433
const tokens = await AsyncStorage.getItem("api:tokens")
434434
if (tokens) {
435-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
436-
const parsedTokens: Tokens = JSON.parse(tokens)
435+
const parsedTokens: Tokens = tokensSchema.parse(JSON.parse(tokens))
437436
console.log("Loaded tokens from local storage")
438437
this.polimiToken = parsedTokens.polimiToken
439438
this.poliNetworkToken = parsedTokens.poliNetworkToken

src/pages/Login.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ import WebView from "react-native-webview"
66
import { usePalette } from "utils/colors"
77
import { api } from "api"
88
import { HttpClient } from "api/HttpClient"
9-
import { PolimiToken, PoliNetworkToken } from "api/schemas"
9+
import {
10+
PolimiToken,
11+
PoliNetworkToken,
12+
poliNetworkTokenSchema,
13+
} from "api/schemas"
1014
import { NavBar } from "components/NavBar"
1115

1216
// TODO: HANDLE ERRORS, this will break as soon as something goes wrong
@@ -132,8 +136,9 @@ export const Login: RootStackScreen<"Login"> = () => {
132136

133137
if (url.startsWith(polinetworkTargetUrl)) {
134138
try {
135-
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
136-
setPoliNetworkToken(JSON.parse(data))
139+
setPoliNetworkToken(
140+
poliNetworkTokenSchema.parse(JSON.parse(data))
141+
)
137142
setCurrentURL(magicTokenUrl)
138143
} catch (e) {
139144
console.log("error while parsing!!")

0 commit comments

Comments
 (0)