From c36b6d2571491b2bbf76f784d740902f282f9b35 Mon Sep 17 00:00:00 2001 From: Arnab Chakraborty <11457760+Rocky43007@users.noreply.github.com> Date: Tue, 30 Jul 2024 16:32:44 +0300 Subject: [PATCH] Actually fetch data from rspc --- apps/desktop/src/App.tsx | 42 +++++++++++++++---- .../settings/client/account/Login.tsx | 1 + .../client/account/handlers/cookieHandler.ts | 12 ++++++ .../settings/client/account/index.tsx | 2 +- interface/index.tsx | 19 --------- 5 files changed, 47 insertions(+), 29 deletions(-) diff --git a/apps/desktop/src/App.tsx b/apps/desktop/src/App.tsx index b8309a53a..dd6ac6693 100644 --- a/apps/desktop/src/App.tsx +++ b/apps/desktop/src/App.tsx @@ -17,14 +17,6 @@ import { RouteTitleContext } from '@sd/interface/hooks/useRouteTitle'; import '@sd/ui/style/style.scss'; -import { useLocale } from '@sd/interface/hooks'; - -import { commands } from './commands'; -import { platform } from './platform'; -import { queryClient } from './query'; -import { createMemoryRouterWithHistory } from './router'; -import { createUpdater } from './updater'; - // TODO: Bring this back once upstream is fixed up. // const client = hooks.createClient({ // links: [ @@ -34,13 +26,45 @@ import { createUpdater } from './updater'; // tauriLink() // ] // }); +import SuperTokens from 'supertokens-web-js'; +import EmailPassword from 'supertokens-web-js/recipe/emailpassword'; +import Session from 'supertokens-web-js/recipe/session'; +import ThirdParty from 'supertokens-web-js/recipe/thirdparty'; +import getCookieHandler, { + setAppReady +} from '@sd/interface/app/$libraryId/settings/client/account/handlers/cookieHandler'; +import getWindowHandler from '@sd/interface/app/$libraryId/settings/client/account/handlers/windowHandler'; +import { useLocale } from '@sd/interface/hooks'; + +import { commands } from './commands'; +import { platform } from './platform'; +import { queryClient } from './query'; +import { createMemoryRouterWithHistory } from './router'; +import { createUpdater } from './updater'; + +SuperTokens.init({ + appInfo: { + apiDomain: 'http://localhost:9420', + apiBasePath: '/api/auth', + appName: 'Spacedrive Auth Service' + }, + cookieHandler: getCookieHandler, + windowHandler: getWindowHandler, + recipeList: [ + Session.init({ tokenTransferMethod: 'header' }), + EmailPassword.init(), + ThirdParty.init() + ] +}); const startupError = (window as any).__SD_ERROR__ as string | undefined; export default function App() { useEffect(() => { // This tells Tauri to show the current window because it's finished loading - commands.appReady(); + commands.appReady().then(() => { + setAppReady(); + }); }, []); useEffect(() => { diff --git a/interface/app/$libraryId/settings/client/account/Login.tsx b/interface/app/$libraryId/settings/client/account/Login.tsx index dce7c310c..9c1cbf720 100644 --- a/interface/app/$libraryId/settings/client/account/Login.tsx +++ b/interface/app/$libraryId/settings/client/account/Login.tsx @@ -44,6 +44,7 @@ async function signInClicked(email: string, password: string) { // this may be a custom error message sent from the API by you. toast.error(err.message); } else { + console.error(err); toast.error('Oops! Something went wrong.'); } } diff --git a/interface/app/$libraryId/settings/client/account/handlers/cookieHandler.ts b/interface/app/$libraryId/settings/client/account/handlers/cookieHandler.ts index f4ac8cb15..bee374a77 100644 --- a/interface/app/$libraryId/settings/client/account/handlers/cookieHandler.ts +++ b/interface/app/$libraryId/settings/client/account/handlers/cookieHandler.ts @@ -1,7 +1,12 @@ import { CookieHandlerInterface } from "supertokens-website/utils/cookieHandler/types"; import { nonLibraryClient } from '@sd/client' +let APP_READY = false; + async function getCookiesFromStorage(): Promise { + if (!APP_READY) { + return ""; + } const cookiesFromStorage = await nonLibraryClient.query(['keys.get']) console.log("Cookies from storage (getCookie): ", cookiesFromStorage); @@ -57,6 +62,9 @@ async function getCookiesFromStorage(): Promise { } async function setCookieToStorage(cookieString: string): Promise { + if (!APP_READY) { + return; + } const cookieName = cookieString.split(";")[0]?.split("=")[0]; console.log("Setting cookie: ", cookieName); @@ -111,3 +119,7 @@ export default function getCookieHandler(original: CookieHandlerInterface): Cook }, }; } + +export function setAppReady() { + APP_READY = true; +} diff --git a/interface/app/$libraryId/settings/client/account/index.tsx b/interface/app/$libraryId/settings/client/account/index.tsx index 751a1c349..a6f1c280e 100644 --- a/interface/app/$libraryId/settings/client/account/index.tsx +++ b/interface/app/$libraryId/settings/client/account/index.tsx @@ -16,7 +16,7 @@ export const Component = () => { useEffect(() => { async function _() { console.log("Token data: ", token.data); - const user_data = await fetch('http://localhost:9000/api/user', { + const user_data = await fetch('http://localhost:9420/api/user', { method: 'GET', headers: { 'Authorization': `Bearer ${token.data ?? ''}` diff --git a/interface/index.tsx b/interface/index.tsx index 4370b2312..1d4d4a8a2 100644 --- a/interface/index.tsx +++ b/interface/index.tsx @@ -5,10 +5,6 @@ import relativeTime from 'dayjs/plugin/relativeTime'; import { PropsWithChildren, Suspense } from 'react'; import { I18nextProvider } from 'react-i18next'; import { RouterProvider, RouterProviderProps } from 'react-router-dom'; -import SuperTokens from 'supertokens-web-js'; -import EmailPassword from 'supertokens-web-js/recipe/emailpassword'; -import Session from 'supertokens-web-js/recipe/session'; -import ThirdParty from 'supertokens-web-js/recipe/thirdparty'; import { InteropProviderReact, P2PContextProvider, @@ -48,21 +44,6 @@ import('@sentry/browser').then(({ init, Integrations }) => { }); }); -SuperTokens.init({ - appInfo: { - apiDomain: 'http://localhost:9000', - apiBasePath: '/api/auth', - appName: 'Spacedrive Auth Service' - }, - cookieHandler: getCookieHandler, - windowHandler: getWindowHandler, - recipeList: [ - Session.init({ tokenTransferMethod: 'header' }), - EmailPassword.init(), - ThirdParty.init() - ] -}); - export type Router = RouterProviderProps['router']; export function SpacedriveRouterProvider(props: {