Merge branch 'window-build' of http://git.hicglobalsolutions.in/BhawanSingh/va-tracker
This commit is contained in:
commit
9ab39832b5
|
|
@ -6,5 +6,5 @@ DNS = 1.1.1.1
|
||||||
[Peer]
|
[Peer]
|
||||||
PublicKey = jG+7H5thEiNjxY1XqI1R9oyMAMTIegLwE3tZkS1Rj2U=
|
PublicKey = jG+7H5thEiNjxY1XqI1R9oyMAMTIegLwE3tZkS1Rj2U=
|
||||||
Endpoint = 35.95.209.161:51820
|
Endpoint = 35.95.209.161:51820
|
||||||
AllowedIPs = 10.0.0.0/32 0.0.0.0/0
|
AllowedIPs = 10.0.0.0/32
|
||||||
PersistentKeepalive = 25
|
PersistentKeepalive = 25
|
||||||
|
|
|
||||||
|
|
@ -4,15 +4,22 @@ import { getToken } from '../utils/tokenHelper.js';
|
||||||
import chalk from "chalk";
|
import chalk from "chalk";
|
||||||
import { sendTokenExpired } from '../ipc/ipcHandler.js';
|
import { sendTokenExpired } from '../ipc/ipcHandler.js';
|
||||||
import https from 'https';
|
import https from 'https';
|
||||||
|
import { getBaseURL } from './baseURL.js';
|
||||||
|
|
||||||
const TOKEN_KEY = 'ACCESS_TOKEN';
|
const TOKEN_KEY = 'ACCESS_TOKEN';
|
||||||
|
|
||||||
|
const Base_URL = await getBaseURL()
|
||||||
|
|
||||||
const httpsAgent = new https.Agent({
|
const httpsAgent = new https.Agent({
|
||||||
rejectUnauthorized: false
|
rejectUnauthorized: false
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
console.log('Base_URL$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$' ,Base_URL)
|
||||||
|
|
||||||
const api: AxiosInstance = axios.create({
|
const api: AxiosInstance = axios.create({
|
||||||
baseURL: 'https://quality-friendly-goldfish.ngrok-free.app/api/v1/va', // 🔁 your backend
|
// baseURL: 'https://quality-friendly-goldfish.ngrok-free.app/api/v1/va', // 🔁 your backend
|
||||||
|
baseURL: `${Base_URL}/api/v1/va`,
|
||||||
httpsAgent
|
httpsAgent
|
||||||
// timeout: 10000,
|
// timeout: 10000,
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
let CURRENT_BASE_URL = "https://quality-friendly-goldfish.ngrok-free.app/api/v1/va";
|
// let CURRENT_BASE_URL = "https://quality-friendly-goldfish.ngrok-free.app/api/v1/va";
|
||||||
|
let CURRENT_BASE_URL = "https://quality-friendly-goldfish.ngrok-free.app";
|
||||||
|
|
||||||
export const getBaseURL = () => CURRENT_BASE_URL;
|
export const getBaseURL = () => CURRENT_BASE_URL;
|
||||||
export const setBaseURL = (url: string) => {
|
export const setBaseURL = (url: string) => {
|
||||||
|
|
|
||||||
|
|
@ -71,7 +71,7 @@ export const handleLogin = async (credentials: { email: string, password: string
|
||||||
try {
|
try {
|
||||||
console.log("➡️ Calling API...");
|
console.log("➡️ Calling API...");
|
||||||
const response = await axios.post(
|
const response = await axios.post(
|
||||||
`https://quality-friendly-goldfish.ngrok-free.app/api/v1/va/login`,
|
`${baseURL}/api/v1/va/login`,
|
||||||
{ userDetails: { ...credentials } },
|
{ userDetails: { ...credentials } },
|
||||||
{ headers: { "ngrok-skip-browser-warning": 69420 }, httpsAgent }
|
{ headers: { "ngrok-skip-browser-warning": 69420 }, httpsAgent }
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -123,9 +123,9 @@ const App: React.FC = () => {
|
||||||
path="/login"
|
path="/login"
|
||||||
element={
|
element={
|
||||||
<PublicRoute user={user}>
|
<PublicRoute user={user}>
|
||||||
{/* <VpnGuard> */}
|
<VpnGuard>
|
||||||
<Login />
|
<Login />
|
||||||
{/* </VpnGuard> */}
|
</VpnGuard>
|
||||||
</PublicRoute>
|
</PublicRoute>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import React, { useEffect, useState } from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
import { Shield, ShieldAlert, RefreshCw, Wifi } from "lucide-react";
|
import { Shield, ShieldAlert, RefreshCw, Wifi, Power } from "lucide-react";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
|
|
@ -8,6 +8,7 @@ interface Props {
|
||||||
const VpnGuard: React.FC<Props> = ({ children }) => {
|
const VpnGuard: React.FC<Props> = ({ children }) => {
|
||||||
|
|
||||||
const VPN_API = "http://10.0.0.2:3000";
|
const VPN_API = "http://10.0.0.2:3000";
|
||||||
|
const DEFAULT_API = "https://quality-friendly-goldfish.ngrok-free.app"
|
||||||
|
|
||||||
const [checking, setChecking] = useState(true);
|
const [checking, setChecking] = useState(true);
|
||||||
const [vpnConnected, setVpnConnected] = useState(true);
|
const [vpnConnected, setVpnConnected] = useState(true);
|
||||||
|
|
@ -19,8 +20,10 @@ const VpnGuard: React.FC<Props> = ({ children }) => {
|
||||||
|
|
||||||
const res = await window.electron?.checkRegion();
|
const res = await window.electron?.checkRegion();
|
||||||
console.log("VpnGuard", res);
|
console.log("VpnGuard", res);
|
||||||
|
setVpnConnected(false);
|
||||||
|
return
|
||||||
|
|
||||||
setVpnConnected(res?.success === true);
|
// setVpnConnected(res?.success === true);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("VPN check failed:", error);
|
console.error("VPN check failed:", error);
|
||||||
setVpnConnected(false);
|
setVpnConnected(false);
|
||||||
|
|
@ -61,6 +64,27 @@ const VpnGuard: React.FC<Props> = ({ children }) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
const disconnectVPN = async () => {
|
||||||
|
setChecking(true);
|
||||||
|
try {
|
||||||
|
const res = await window.electron.disconnectVPN();;
|
||||||
|
console.log("disconnectVPN →", res);
|
||||||
|
|
||||||
|
// Restore original base URL
|
||||||
|
const baseRes = await window.electron.updateBaseURL(DEFAULT_API);
|
||||||
|
console.log("baseRes disconnect →", baseRes);
|
||||||
|
|
||||||
|
setVpnConnected(true);
|
||||||
|
|
||||||
|
// await checkVPN();
|
||||||
|
} catch (error) {
|
||||||
|
console.log("Disconnect Error:", error);
|
||||||
|
} finally {
|
||||||
|
setChecking(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
// Checking state
|
// Checking state
|
||||||
if (checking && !isRetrying) {
|
if (checking && !isRetrying) {
|
||||||
return (
|
return (
|
||||||
|
|
@ -93,7 +117,8 @@ const VpnGuard: React.FC<Props> = ({ children }) => {
|
||||||
<div className="max-w-md w-full">
|
<div className="max-w-md w-full">
|
||||||
<div className="card bg-base-100 shadow-2xl">
|
<div className="card bg-base-100 shadow-2xl">
|
||||||
<div className="card-body items-center text-center">
|
<div className="card-body items-center text-center">
|
||||||
{/* Icon with animation */}
|
|
||||||
|
{/* Icon */}
|
||||||
<div className="relative mb-4">
|
<div className="relative mb-4">
|
||||||
<div className="absolute inset-0 flex items-center justify-center">
|
<div className="absolute inset-0 flex items-center justify-center">
|
||||||
<div className="w-20 h-20 border-4 border-error opacity-20 rounded-full animate-pulse"></div>
|
<div className="w-20 h-20 border-4 border-error opacity-20 rounded-full animate-pulse"></div>
|
||||||
|
|
@ -103,21 +128,16 @@ const VpnGuard: React.FC<Props> = ({ children }) => {
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Title */}
|
<h2 className="card-title text-3xl mb-3">VPN Required</h2>
|
||||||
<h2 className="card-title text-3xl mb-3">
|
|
||||||
VPN Required
|
|
||||||
</h2>
|
|
||||||
|
|
||||||
{/* Description */}
|
|
||||||
<p className="mb-6 opacity-80">
|
<p className="mb-6 opacity-80">
|
||||||
Please connect to your company VPN to access this application.
|
Please connect to your company VPN to access this application.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
{/* Retry button */}
|
{/* Connect VPN */}
|
||||||
<button
|
<button
|
||||||
className="btn btn-primary btn-wide gap-2"
|
className="btn btn-primary btn-wide gap-2"
|
||||||
onClick={connectVPN}
|
onClick={connectVPN}
|
||||||
disabled={isRetrying}
|
disabled={isRetrying || vpnConnected} // Disable if retrying OR already connected
|
||||||
>
|
>
|
||||||
{isRetrying ? (
|
{isRetrying ? (
|
||||||
<>
|
<>
|
||||||
|
|
@ -132,12 +152,21 @@ const VpnGuard: React.FC<Props> = ({ children }) => {
|
||||||
)}
|
)}
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
{/* Help text */}
|
{/* Disconnect VPN (Disabled when NOT connected) */}
|
||||||
|
<button
|
||||||
|
className="btn btn-error btn-wide gap-2 mt-3"
|
||||||
|
onClick={disconnectVPN}
|
||||||
|
// disabled={!vpnConnected || checking} // Disable if not connected
|
||||||
|
>
|
||||||
|
<Power className="w-4 h-4" />
|
||||||
|
Disconnect VPN
|
||||||
|
</button>
|
||||||
|
|
||||||
<div className="divider"></div>
|
<div className="divider"></div>
|
||||||
<p className="text-xs opacity-60">
|
<p className="text-xs opacity-60">
|
||||||
Need help? Contact IT support at{" "}
|
Need help? Contact IT support at{" "}
|
||||||
<a href="mailto:support@company.com" className="link link-primary">
|
<a href="mailto:support@docva.com" className="link link-primary">
|
||||||
support@company.com
|
support@docva.com
|
||||||
</a>
|
</a>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -147,7 +176,12 @@ const VpnGuard: React.FC<Props> = ({ children }) => {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return <>{children}</>;
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{children}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue