fix?
This commit is contained in:
@ -1,8 +1,6 @@
|
||||
import { Navigate } from "@solidjs/router";
|
||||
import { platform } from "@tauri-apps/plugin-os";
|
||||
import { jwtDecode } from "jwt-decode";
|
||||
import { Component, createSignal, ParentProps, Show } from "solid-js";
|
||||
import { save_token } from "tauri-plugin-ios-shared-token-api";
|
||||
import { Component, ParentProps, Show } from "solid-js";
|
||||
import { InferOutput, literal, number, object, parse, pipe, string, transform } from "valibot";
|
||||
|
||||
export const isTokenValid = (): boolean => {
|
||||
@ -34,29 +32,16 @@ export const getTokenProperties = (token: string): InferOutput<typeof accessToke
|
||||
|
||||
export const ProtectedRoute: Component<ParentProps> = (props) => {
|
||||
const isValid = isTokenValid();
|
||||
const [error, setError] = createSignal<string | undefined>();
|
||||
|
||||
if (isValid) {
|
||||
const token = localStorage.getItem("refresh");
|
||||
if (token == null) {
|
||||
throw new Error("unreachable");
|
||||
}
|
||||
|
||||
if (platform() === "ios") {
|
||||
// iOS share extension is a seperate process to the App.
|
||||
// Therefore, we need to share our access token somewhere both the App & Share Extension can access
|
||||
// This involves App Groups.
|
||||
save_token(token)
|
||||
.then(() => console.log("Saved token!!!"))
|
||||
.catch((e) => setError("Couldnt save token: " + e));
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<Show when={isValid} fallback={<Navigate href="/login" />}>
|
||||
<Show when={error()}>
|
||||
{e => <h2 class="text-2xl font-bold">{e()}</h2>}
|
||||
</Show>
|
||||
{props.children}
|
||||
</Show>
|
||||
);
|
||||
|
@ -1,5 +1,7 @@
|
||||
import { getTokenProperties } from "@components/protected-route";
|
||||
import { fetch } from "@tauri-apps/plugin-http";
|
||||
import { platform } from "@tauri-apps/plugin-os";
|
||||
import { save_token } from "tauri-plugin-ios-shared-token-api";
|
||||
|
||||
import {
|
||||
type InferOutput,
|
||||
@ -45,6 +47,17 @@ export const getAccessToken = async (): Promise<string> => {
|
||||
throw new Error("you are not logged in")
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (platform() === "ios") {
|
||||
// iOS share extension is a seperate process to the App.
|
||||
// Therefore, we need to share our access token somewhere both the App & Share Extension can access
|
||||
// This involves App Groups.
|
||||
save_token(refreshToken!)
|
||||
.then(() => console.log("Saved token!!!"))
|
||||
.catch(console.error);
|
||||
}
|
||||
|
||||
// FIX: Check what getTokenProperties returns
|
||||
const tokenProps = getTokenProperties(accessToken!);
|
||||
|
||||
|
@ -24,6 +24,7 @@ class SharedToken: Plugin {
|
||||
}
|
||||
|
||||
sharedDefaults.set(token, forKey: sharedTokenKey)
|
||||
sharedDefaults.synchronize()
|
||||
invoke.resolve()
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user