another fix
This commit is contained in:
@ -1,7 +1,7 @@
|
|||||||
import { Navigate } from "@solidjs/router";
|
import { Navigate } from "@solidjs/router";
|
||||||
import { platform } from "@tauri-apps/plugin-os";
|
import { platform } from "@tauri-apps/plugin-os";
|
||||||
import { jwtDecode } from "jwt-decode";
|
import { jwtDecode } from "jwt-decode";
|
||||||
import { Component, ParentProps, Show } from "solid-js";
|
import { Component, createSignal, ParentProps, Show } from "solid-js";
|
||||||
import { save_token } from "tauri-plugin-ios-shared-token-api";
|
import { save_token } from "tauri-plugin-ios-shared-token-api";
|
||||||
import { InferOutput, literal, number, object, parse, pipe, string, transform } from "valibot";
|
import { InferOutput, literal, number, object, parse, pipe, string, transform } from "valibot";
|
||||||
|
|
||||||
@ -34,6 +34,7 @@ export const getTokenProperties = (token: string): InferOutput<typeof accessToke
|
|||||||
|
|
||||||
export const ProtectedRoute: Component<ParentProps> = (props) => {
|
export const ProtectedRoute: Component<ParentProps> = (props) => {
|
||||||
const isValid = isTokenValid();
|
const isValid = isTokenValid();
|
||||||
|
const [error, setError] = createSignal<string | undefined>();
|
||||||
|
|
||||||
if (isValid) {
|
if (isValid) {
|
||||||
const token = localStorage.getItem("refresh");
|
const token = localStorage.getItem("refresh");
|
||||||
@ -47,12 +48,15 @@ export const ProtectedRoute: Component<ParentProps> = (props) => {
|
|||||||
// This involves App Groups.
|
// This involves App Groups.
|
||||||
save_token(token)
|
save_token(token)
|
||||||
.then(() => console.log("Saved token!!!"))
|
.then(() => console.log("Saved token!!!"))
|
||||||
.catch((e) => console.error(e));
|
.catch((e) => setError("Couldnt save token: " + e));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Show when={isValid} fallback={<Navigate href="/login" />}>
|
<Show when={isValid} fallback={<Navigate href="/login" />}>
|
||||||
|
<Show when={error()}>
|
||||||
|
{e => <h2 class="text-2xl font-bold">{e()}</h2>}
|
||||||
|
</Show>
|
||||||
{props.children}
|
{props.children}
|
||||||
</Show>
|
</Show>
|
||||||
);
|
);
|
||||||
|
Reference in New Issue
Block a user