organizing things and cracking problem with the polyfills i think?
This commit is contained in:
@@ -1,7 +1,5 @@
|
|||||||
import Login from "../../pages/Login";
|
import Login from "../../pages/Login";
|
||||||
import { STORE_ITEMS } from "../../electron/store";
|
|
||||||
import SkeletonLoader from "../loading/skeleton";
|
import SkeletonLoader from "../loading/skeleton";
|
||||||
import { nirvanaApi } from "../../controller/nirvanaApi";
|
|
||||||
import { useEffect } from "react";
|
import { useEffect } from "react";
|
||||||
import { useGetUserDetails } from "../../controller/index";
|
import { useGetUserDetails } from "../../controller/index";
|
||||||
|
|
||||||
@@ -12,11 +10,6 @@ export default function ProtectedRoute({
|
|||||||
}) {
|
}) {
|
||||||
const { isLoading, isError, refetch } = useGetUserDetails();
|
const { isLoading, isError, refetch } = useGetUserDetails();
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
// console.log(window.electronAPI.store.get(STORE_ITEMS.AUTH_TOKENS));
|
|
||||||
// nirvanaApi.getUserDetails();
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
if (isLoading)
|
if (isLoading)
|
||||||
return (
|
return (
|
||||||
<div className="container h-screen w-screen">
|
<div className="container h-screen w-screen">
|
||||||
|
|||||||
@@ -1,6 +1,13 @@
|
|||||||
|
// NOTE: DO NOT ADD ANY ELECTRON RELATED TYPESCRIPT HERE...KEEP IT ONLY TYPESCRIPT OTHERWISE
|
||||||
|
// THE RENDERED WONT BE ABLE TO ACCESS THIS AS IT WILL THINK ITS PART OF MAIN PROCESS
|
||||||
|
|
||||||
enum Channels {
|
enum Channels {
|
||||||
ACTIVATE_LOG_IN = "ACTIVATE_LOG_IN",
|
ACTIVATE_LOG_IN = "ACTIVATE_LOG_IN",
|
||||||
AUTH_TOKENS = "AUTH_TOKENS",
|
AUTH_TOKENS = "AUTH_TOKENS",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export enum STORE_ITEMS {
|
||||||
|
AUTH_TOKENS = "AUTH_TOKENS",
|
||||||
|
}
|
||||||
|
|
||||||
export default Channels;
|
export default Channels;
|
||||||
|
|||||||
+11
-1
@@ -3,6 +3,16 @@ import { electronAPI } from "./preload";
|
|||||||
export {};
|
export {};
|
||||||
declare global {
|
declare global {
|
||||||
interface Window {
|
interface Window {
|
||||||
electronAPI: typeof electronAPI;
|
electronAPI: {
|
||||||
|
auth: {
|
||||||
|
initiateLogin(): void;
|
||||||
|
};
|
||||||
|
store: {
|
||||||
|
get(val: STORE_ITEMS): any;
|
||||||
|
set(property: STORE_ITEMS, val: any): void;
|
||||||
|
};
|
||||||
|
on(channel: Channels, func: any): void;
|
||||||
|
once(channel: Channels, func: any): void;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import store, { STORE_ITEMS } from "./store";
|
import Channels, { STORE_ITEMS } from "./constants";
|
||||||
|
|
||||||
import Channels from "./constants";
|
|
||||||
import ElectronGoogleOAuth2 from "@getstation/electron-google-oauth2";
|
import ElectronGoogleOAuth2 from "@getstation/electron-google-oauth2";
|
||||||
import { browserWindow } from "../index";
|
import { browserWindow } from "../index";
|
||||||
import { ipcMain } from "electron";
|
import { ipcMain } from "electron";
|
||||||
|
import store from "./store";
|
||||||
|
|
||||||
const myApiOauth = new ElectronGoogleOAuth2(
|
const myApiOauth = new ElectronGoogleOAuth2(
|
||||||
"423533244953-banligobgbof8hg89i6cr1l7u0p7c2pk.apps.googleusercontent.com",
|
"423533244953-banligobgbof8hg89i6cr1l7u0p7c2pk.apps.googleusercontent.com",
|
||||||
@@ -12,6 +12,7 @@ const myApiOauth = new ElectronGoogleOAuth2(
|
|||||||
{ successRedirectURL: "https://usenirvana.com" }
|
{ successRedirectURL: "https://usenirvana.com" }
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// FRESH LOGIN...either tokens of user expired or never had them
|
||||||
export async function handleLogin() {
|
export async function handleLogin() {
|
||||||
// read saved refresh token if any
|
// read saved refresh token if any
|
||||||
// todo: fix this...should be working
|
// todo: fix this...should be working
|
||||||
|
|||||||
@@ -1,26 +1,42 @@
|
|||||||
import { contextBridge, ipcRenderer } from "electron";
|
import { contextBridge, ipcRenderer } from "electron";
|
||||||
|
|
||||||
import Channels from "./constants";
|
import Channels from "./constants";
|
||||||
import { STORE_ITEMS } from "./store";
|
import { STORE_ITEMS } from "./constants";
|
||||||
|
|
||||||
const electronAPI = {
|
const electronAPI = {
|
||||||
auth: {
|
auth: {
|
||||||
initiateLogin() {
|
initiateLogin() {
|
||||||
ipcRenderer.send(Channels.ACTIVATE_LOG_IN);
|
ipcRenderer.send(Channels.ACTIVATE_LOG_IN);
|
||||||
},
|
},
|
||||||
receiveTokens(channel: Channels, func: any) {
|
|
||||||
ipcRenderer.on(channel, (event, ...args) => func(...args));
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
store: {
|
store: {
|
||||||
get(val: STORE_ITEMS) {
|
get(val: STORE_ITEMS) {
|
||||||
return ipcRenderer.sendSync("electron-store-get", val);
|
return ipcRenderer.invoke("electron-store-get", val);
|
||||||
},
|
},
|
||||||
set(property: STORE_ITEMS, val: any) {
|
set(property: STORE_ITEMS, val: any) {
|
||||||
ipcRenderer.send("electron-store-set", property, val);
|
ipcRenderer.send("electron-store-set", property, val);
|
||||||
},
|
},
|
||||||
// Other method you want to add like has(), reset(), etc.
|
// Other method you want to add like has(), reset(), etc.
|
||||||
},
|
},
|
||||||
|
|
||||||
|
on(channel: Channels, func: any) {
|
||||||
|
const validChannels = ["ipc-example"];
|
||||||
|
// if (validChannels.includes(channel)) {
|
||||||
|
// // Deliberately strip event as it includes `sender`
|
||||||
|
// ipcRenderer.on(channel, (event, ...args) => func(...args));
|
||||||
|
// }
|
||||||
|
|
||||||
|
ipcRenderer.on(channel, (event, ...args) => func(...args));
|
||||||
|
},
|
||||||
|
once(channel: Channels, func: any) {
|
||||||
|
// const validChannels = ["ipc-example"];
|
||||||
|
// if (validChannels.includes(channel)) {
|
||||||
|
// // Deliberately strip event as it includes `sender`
|
||||||
|
// ipcRenderer.once(channel, (event, ...args) => func(...args));
|
||||||
|
// }
|
||||||
|
|
||||||
|
ipcRenderer.once(channel, (event, ...args) => func(...args));
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
contextBridge.exposeInMainWorld("electronAPI", electronAPI);
|
contextBridge.exposeInMainWorld("electronAPI", electronAPI);
|
||||||
|
|||||||
@@ -2,8 +2,4 @@ import Store from "electron-store";
|
|||||||
import { ipcMain } from "electron";
|
import { ipcMain } from "electron";
|
||||||
const store = new Store();
|
const store = new Store();
|
||||||
|
|
||||||
export enum STORE_ITEMS {
|
|
||||||
AUTH_TOKENS = "AUTH_TOKENS",
|
|
||||||
}
|
|
||||||
|
|
||||||
export default store;
|
export default store;
|
||||||
|
|||||||
@@ -45,18 +45,20 @@ app
|
|||||||
.whenReady()
|
.whenReady()
|
||||||
.then(createWindow)
|
.then(createWindow)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
|
// activate login
|
||||||
ipcMain.on(Channels.ACTIVATE_LOG_IN, async (event, arg) => {
|
ipcMain.on(Channels.ACTIVATE_LOG_IN, async (event, arg) => {
|
||||||
console.log("initiating log in");
|
console.log("initiating log in");
|
||||||
await handleLogin();
|
await handleLogin();
|
||||||
});
|
});
|
||||||
|
|
||||||
// IPC listener
|
// IPC listener
|
||||||
ipcMain.on("electron-store-get", async (event, val) => {
|
|
||||||
event.returnValue = store.get(val);
|
|
||||||
});
|
|
||||||
ipcMain.on("electron-store-set", async (event, key, val) => {
|
ipcMain.on("electron-store-set", async (event, key, val) => {
|
||||||
store.set(key, val);
|
store.set(key, val);
|
||||||
});
|
});
|
||||||
|
ipcMain.handle("electron-store-get", async (event, val) => {
|
||||||
|
const result = await store.get(val);
|
||||||
|
return result;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// Quit when all windows are closed, except on macOS. There, it's common
|
// Quit when all windows are closed, except on macOS. There, it's common
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import Channels from "../../electron/constants";
|
|||||||
import { CircularProgress } from "@mui/material";
|
import { CircularProgress } from "@mui/material";
|
||||||
import { FcGoogle } from "react-icons/fc";
|
import { FcGoogle } from "react-icons/fc";
|
||||||
import Logo from "../../components/Logo";
|
import Logo from "../../components/Logo";
|
||||||
|
// import { STORE_ITEMS } from "../../electron/store";
|
||||||
import { nirvanaApi } from "../../controller/nirvanaApi";
|
import { nirvanaApi } from "../../controller/nirvanaApi";
|
||||||
import { useCreateUser } from "../../controller/index";
|
import { useCreateUser } from "../../controller/index";
|
||||||
import { useSetRecoilState } from "recoil";
|
import { useSetRecoilState } from "recoil";
|
||||||
@@ -19,22 +20,46 @@ export default function Login({ onReady }: { onReady: Function }) {
|
|||||||
window.electronAPI.auth.initiateLogin();
|
window.electronAPI.auth.initiateLogin();
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
const setAccessTokensAndContinue = (tokens: {
|
||||||
window.electronAPI.auth.receiveTokens(
|
accessToken: string;
|
||||||
Channels.AUTH_TOKENS,
|
idToken: string;
|
||||||
(tokens: any) => {
|
refreshToken: string;
|
||||||
// todo: implement refresh token procedure in api layer by sending refresh_token and such
|
}) => {
|
||||||
const { access_token, id_token, refresh_token } = tokens;
|
setAuthTokens(tokens);
|
||||||
setAuthTokens({
|
|
||||||
accessToken: access_token,
|
|
||||||
idToken: id_token,
|
|
||||||
refreshToken: refresh_token,
|
|
||||||
});
|
|
||||||
|
|
||||||
// now can go to home and get authenticated regardless of type of user
|
onReady();
|
||||||
onReady();
|
};
|
||||||
}
|
|
||||||
);
|
useEffect(() => {
|
||||||
|
// see if we have tokens in localstorage in which case we can continue on
|
||||||
|
// const tokensFromStore: any = window.electronAPI.store.get(
|
||||||
|
// STORE_ITEMS.AUTH_TOKENS
|
||||||
|
// );
|
||||||
|
|
||||||
|
// if (tokensFromStore) {
|
||||||
|
// setIsLoading(true);
|
||||||
|
|
||||||
|
// const { access_token, id_token, refresh_token } = tokensFromStore;
|
||||||
|
|
||||||
|
// setAccessTokensAndContinue({
|
||||||
|
// accessToken: access_token,
|
||||||
|
// idToken: id_token,
|
||||||
|
// refreshToken: refresh_token,
|
||||||
|
// });
|
||||||
|
// }
|
||||||
|
|
||||||
|
window.electronAPI.once(Channels.AUTH_TOKENS, (tokens: any) => {
|
||||||
|
setIsLoading(true);
|
||||||
|
|
||||||
|
// todo: implement refresh token procedure in api layer by sending refresh_token and such
|
||||||
|
const { access_token, id_token, refresh_token } = tokens;
|
||||||
|
|
||||||
|
setAccessTokensAndContinue({
|
||||||
|
accessToken: access_token,
|
||||||
|
idToken: id_token,
|
||||||
|
refreshToken: refresh_token,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
// todo: figure out how to clean up with the preload api
|
// todo: figure out how to clean up with the preload api
|
||||||
// return () => {
|
// return () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user