feat: use ipc to overcome cors

This commit is contained in:
Anoop M D 2022-03-09 01:15:26 +05:30
parent 6e6d8d4c92
commit 7ee80298f9
3 changed files with 35 additions and 8 deletions

View File

@ -1,6 +1,7 @@
// Native
const { join } = require('path');
const { format } = require('url');
const axios = require('axios');
// Packages
const { BrowserWindow, app, ipcMain } = require('electron');
@ -15,7 +16,8 @@ app.on('ready', async () => {
width: 1280,
height: 768,
webPreferences: {
nodeIntegration: false,
nodeIntegration: true,
contextIsolation: false,
preload: join(__dirname, 'preload.js'),
},
});
@ -38,3 +40,9 @@ app.on('window-all-closed', app.quit);
ipcMain.on('message', (event, message) => {
event.sender.send('message', message);
});
// handler for all request related to a user's grafnode account
ipcMain.handle('grafnode-account-request', async (_, request) => {
const result = await axios(request)
return { data: result.data, status: result.status }
})

View File

@ -1,13 +1,25 @@
import { get, post, put } from './base';
const AuthApi = {
whoami: () =>get('auth/v1/user/whoami'),
signup: (params) =>post('auth/v1/user/signup', params),
login: (params) =>post('auth/v1/user/login', params),
whoami: () => get('auth/v1/user/whoami'),
signup: (params) => post('auth/v1/user/signup', params),
login: (params) => {
return new Promise((resolve, reject) => {
const { ipcRenderer } = window.require("electron");
ipcRenderer.invoke('grafnode-account-request', {
data: params,
method: 'POST',
url: `${process.env.NEXT_PUBLIC_GRAFNODE_SERVER_API}/auth/v1/user/login`,
})
.then(resolve)
.catch(reject);
});
},
signout: () => post('auth/v1/user/logout'),
getProfile: () =>get('auth/v1/user/profile'),
updateProfile: (params) =>put('auth/v1/user/profile', params),
updateUsername: (params) =>put('auth/v1/user/username', params)
getProfile: () => get('auth/v1/user/profile'),
updateProfile: (params) => put('auth/v1/user/profile', params),
updateUsername: (params) => put('auth/v1/user/username', params)
};
export default AuthApi;

View File

@ -1,3 +1,10 @@
module.exports = {
reactStrictMode: true,
}
webpack: (config, { isServer }) => {
// Fixes npm packages that depend on `fs` module
if (!isServer) {
config.resolve.fallback.fs = false;
}
return config;
},
};