Compare commits

..

No commits in common. "3fbe5ea039af3dd5bf8c7166f6d2bbe6d5fd306e" and "45a967644ca8d06404241013927e688794a67a55" have entirely different histories.

3 changed files with 31 additions and 41 deletions

View file

@ -1,7 +1,7 @@
const nextConfig = { const nextConfig = {
output: 'export', output: 'export',
env: { env: {
NEXT_PUBLIC_API_URL: process.env.NEXT_PUBLIC_API_URL || 'https://api.litenet.tel', NEXT_PUBLIC_API_URL: process.env.NEXT_PUBLIC_API_URL || 'http://localhost:3001',
}, },
}; };

View file

@ -1,48 +1,16 @@
"use client"; "use client";
import React, { createContext, useContext, useState, useEffect, useCallback, Suspense } from 'react'; import React, { createContext, useContext, useState, useEffect, useCallback } from 'react';
import { useRouter, useSearchParams } from 'next/navigation'; import { useRouter, useSearchParams } from 'next/navigation';
const AuthContext = createContext(null); const AuthContext = createContext(null);
function AuthHandler({ setToken, setNoExtension, setLoading, children }) {
const router = useRouter();
const searchParams = useSearchParams();
useEffect(() => {
const tokenFromParams = searchParams.get('token');
if (tokenFromParams) {
if (tokenFromParams === 'noext.0') {
setNoExtension(true);
setToken(null);
localStorage.removeItem('session_token');
} else {
setToken(tokenFromParams);
localStorage.setItem('session_token', tokenFromParams);
setNoExtension(false);
}
// Clean URL
router.replace('/dashboard', undefined, { shallow: true });
}
}, [searchParams, router, setToken, setNoExtension]);
useEffect(() => {
const storedToken = localStorage.getItem('session_token');
if (storedToken) {
setToken(storedToken);
setNoExtension(false);
}
setLoading(false);
}, [setLoading, setToken, setNoExtension]);
return <>{children}</>;
}
export function AuthProvider({ children }) { export function AuthProvider({ children }) {
const [token, setToken] = useState(null); const [token, setToken] = useState(null);
const [noExtension, setNoExtension] = useState(false); const [noExtension, setNoExtension] = useState(false);
const [loading, setLoading] = useState(true); const [loading, setLoading] = useState(true);
const router = useRouter(); const router = useRouter();
const searchParams = useSearchParams();
const logout = useCallback(async () => { const logout = useCallback(async () => {
if (token) { if (token) {
@ -61,6 +29,32 @@ export function AuthProvider({ children }) {
router.push('/dashboard'); router.push('/dashboard');
}, [token, router]); }, [token, router]);
useEffect(() => {
const tokenFromParams = searchParams.get('token');
const storedToken = localStorage.getItem('session_token');
if (tokenFromParams) {
if (tokenFromParams === 'noext.0') {
setNoExtension(true);
setToken(null);
localStorage.removeItem('session_token');
} else {
setToken(tokenFromParams);
localStorage.setItem('session_token', tokenFromParams);
setNoExtension(false);
}
setLoading(false);
// Clean URL
router.replace('/dashboard', undefined, { shallow: true });
} else if (storedToken) {
setToken(storedToken);
setNoExtension(false);
setLoading(false);
} else {
setLoading(false);
}
}, [searchParams, router]);
const value = { const value = {
token, token,
isLoggedIn: !!token, isLoggedIn: !!token,
@ -71,11 +65,7 @@ export function AuthProvider({ children }) {
return ( return (
<AuthContext.Provider value={value}> <AuthContext.Provider value={value}>
<Suspense fallback={null}> {children}
<AuthHandler setToken={setToken} setNoExtension={setNoExtension} setLoading={setLoading}>
{children}
</AuthHandler>
</Suspense>
</AuthContext.Provider> </AuthContext.Provider>
); );
} }

View file

@ -4,7 +4,7 @@ export const updates = [
{ {
id: 4, id: 4,
title: "Web Dashboard Release", title: "Web Dashboard Release",
timestamp: "2025-07-14T12:00:00Z", timestamp: "2025-07-06T12:00:00Z",
author: Authors.ROCORD, author: Authors.ROCORD,
summary: "Introducing the new LiteNet Web Dashboard", summary: "Introducing the new LiteNet Web Dashboard",
content: ` content: `