From 94840a93dd36667b19cfde6cc2f796489f6ec085 Mon Sep 17 00:00:00 2001 From: JaiPandey425 Date: Thu, 11 Dec 2025 14:05:33 +0530 Subject: [PATCH] add vpn v2 --- resources/wireguard/windows/wg0.conf | 2 +- src/electron/api/axiosClient.ts | 13 ++++-- src/electron/api/baseURL.ts | 3 +- src/electron/utils/utilityFunctions.ts | 2 +- src/ui/App.tsx | 4 +- src/ui/pages/Vpn/VpnGuard.tsx | 64 ++++++++++++++++++++------ 6 files changed, 65 insertions(+), 23 deletions(-) diff --git a/resources/wireguard/windows/wg0.conf b/resources/wireguard/windows/wg0.conf index 69a3e03..fa2a861 100644 --- a/resources/wireguard/windows/wg0.conf +++ b/resources/wireguard/windows/wg0.conf @@ -6,5 +6,5 @@ DNS = 1.1.1.1 [Peer] PublicKey = jG+7H5thEiNjxY1XqI1R9oyMAMTIegLwE3tZkS1Rj2U= 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 diff --git a/src/electron/api/axiosClient.ts b/src/electron/api/axiosClient.ts index 1ba36c5..bb23df0 100644 --- a/src/electron/api/axiosClient.ts +++ b/src/electron/api/axiosClient.ts @@ -4,15 +4,22 @@ import { getToken } from '../utils/tokenHelper.js'; import chalk from "chalk"; import { sendTokenExpired } from '../ipc/ipcHandler.js'; import https from 'https'; +import { getBaseURL } from './baseURL.js'; const TOKEN_KEY = 'ACCESS_TOKEN'; +const Base_URL = await getBaseURL() + const httpsAgent = new https.Agent({ rejectUnauthorized: false }); + +console.log('Base_URL$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$' ,Base_URL) + 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 // timeout: 10000, }); @@ -29,7 +36,7 @@ api.interceptors.request.use( if (token) { config.headers['token'] = token; - config.headers['ngrok-skip-browser-warning'] = 'true'; + config.headers['ngrok-skip-browser-warning'] = 'true'; } return config; @@ -54,7 +61,7 @@ api.interceptors.response.use( (response: AxiosResponse) => response.data, async (error) => { - console.log(error , "Line 46") + console.log(error, "Line 46") const status = error?.response?.status; console.error('[Axios Error]', status); diff --git a/src/electron/api/baseURL.ts b/src/electron/api/baseURL.ts index f380736..67478cd 100644 --- a/src/electron/api/baseURL.ts +++ b/src/electron/api/baseURL.ts @@ -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 setBaseURL = (url: string) => { diff --git a/src/electron/utils/utilityFunctions.ts b/src/electron/utils/utilityFunctions.ts index 87e8175..d8523d5 100644 --- a/src/electron/utils/utilityFunctions.ts +++ b/src/electron/utils/utilityFunctions.ts @@ -71,7 +71,7 @@ export const handleLogin = async (credentials: { email: string, password: string try { console.log("➡️ Calling API..."); const response = await axios.post( - `https://quality-friendly-goldfish.ngrok-free.app/api/v1/va/login`, + `${baseURL}/api/v1/va/login`, { userDetails: { ...credentials } }, { headers: { "ngrok-skip-browser-warning": 69420 }, httpsAgent } ); diff --git a/src/ui/App.tsx b/src/ui/App.tsx index 9852676..b55a71b 100644 --- a/src/ui/App.tsx +++ b/src/ui/App.tsx @@ -123,9 +123,9 @@ const App: React.FC = () => { path="/login" element={ - {/* */} + - {/* */} + } /> diff --git a/src/ui/pages/Vpn/VpnGuard.tsx b/src/ui/pages/Vpn/VpnGuard.tsx index 9bf8c2f..609dc36 100644 --- a/src/ui/pages/Vpn/VpnGuard.tsx +++ b/src/ui/pages/Vpn/VpnGuard.tsx @@ -1,5 +1,5 @@ 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 { children: React.ReactNode; @@ -8,6 +8,7 @@ interface Props { const VpnGuard: React.FC = ({ children }) => { 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 [vpnConnected, setVpnConnected] = useState(true); @@ -19,8 +20,10 @@ const VpnGuard: React.FC = ({ children }) => { const res = await window.electron?.checkRegion(); console.log("VpnGuard", res); + setVpnConnected(false); + return - setVpnConnected(res?.success === true); + // setVpnConnected(res?.success === true); } catch (error) { console.error("VPN check failed:", error); setVpnConnected(false); @@ -61,6 +64,27 @@ const VpnGuard: React.FC = ({ 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 if (checking && !isRetrying) { return ( @@ -93,7 +117,8 @@ const VpnGuard: React.FC = ({ children }) => {
- {/* Icon with animation */} + + {/* Icon */}
@@ -103,21 +128,16 @@ const VpnGuard: React.FC = ({ children }) => {
- {/* Title */} -

- VPN Required -

- - {/* Description */} +

VPN Required

Please connect to your company VPN to access this application.

- {/* Retry button */} + {/* Connect VPN */} - {/* Help text */} + {/* Disconnect VPN (Disabled when NOT connected) */} + +

Need help? Contact IT support at{" "} - - support@company.com + + support@docva.com

@@ -147,7 +176,12 @@ const VpnGuard: React.FC = ({ children }) => { ); } - return <>{children}; + + return ( + <> + {children} + + ); };