fix?
This commit is contained in:
@ -1,8 +1,6 @@
|
|||||||
import { Navigate } from "@solidjs/router";
|
import { Navigate } from "@solidjs/router";
|
||||||
import { platform } from "@tauri-apps/plugin-os";
|
|
||||||
import { jwtDecode } from "jwt-decode";
|
import { jwtDecode } from "jwt-decode";
|
||||||
import { Component, createSignal, ParentProps, Show } from "solid-js";
|
import { Component, ParentProps, Show } from "solid-js";
|
||||||
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";
|
||||||
|
|
||||||
export const isTokenValid = (): boolean => {
|
export const isTokenValid = (): boolean => {
|
||||||
@ -34,29 +32,16 @@ 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");
|
||||||
if (token == null) {
|
if (token == null) {
|
||||||
throw new Error("unreachable");
|
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 (
|
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>
|
||||||
);
|
);
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
import { getTokenProperties } from "@components/protected-route";
|
import { getTokenProperties } from "@components/protected-route";
|
||||||
import { fetch } from "@tauri-apps/plugin-http";
|
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 {
|
import {
|
||||||
type InferOutput,
|
type InferOutput,
|
||||||
@ -45,6 +47,17 @@ export const getAccessToken = async (): Promise<string> => {
|
|||||||
throw new Error("you are not logged in")
|
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
|
// FIX: Check what getTokenProperties returns
|
||||||
const tokenProps = getTokenProperties(accessToken!);
|
const tokenProps = getTokenProperties(accessToken!);
|
||||||
|
|
||||||
|
@ -24,6 +24,7 @@ class SharedToken: Plugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sharedDefaults.set(token, forKey: sharedTokenKey)
|
sharedDefaults.set(token, forKey: sharedTokenKey)
|
||||||
|
sharedDefaults.synchronize()
|
||||||
invoke.resolve()
|
invoke.resolve()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user