Compare commits
2 commits
45a967644c
...
3fbe5ea039
Author | SHA1 | Date | |
---|---|---|---|
|
3fbe5ea039 | ||
|
baa59654db |
|
@ -1,7 +1,7 @@
|
||||||
const nextConfig = {
|
const nextConfig = {
|
||||||
output: 'export',
|
output: 'export',
|
||||||
env: {
|
env: {
|
||||||
NEXT_PUBLIC_API_URL: process.env.NEXT_PUBLIC_API_URL || 'http://localhost:3001',
|
NEXT_PUBLIC_API_URL: process.env.NEXT_PUBLIC_API_URL || 'https://api.litenet.tel',
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,16 +1,48 @@
|
||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import React, { createContext, useContext, useState, useEffect, useCallback } from 'react';
|
import React, { createContext, useContext, useState, useEffect, useCallback, Suspense } 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) {
|
||||||
|
@ -29,32 +61,6 @@ 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,
|
||||||
|
@ -65,7 +71,11 @@ export function AuthProvider({ children }) {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<AuthContext.Provider value={value}>
|
<AuthContext.Provider value={value}>
|
||||||
|
<Suspense fallback={null}>
|
||||||
|
<AuthHandler setToken={setToken} setNoExtension={setNoExtension} setLoading={setLoading}>
|
||||||
{children}
|
{children}
|
||||||
|
</AuthHandler>
|
||||||
|
</Suspense>
|
||||||
</AuthContext.Provider>
|
</AuthContext.Provider>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ export const updates = [
|
||||||
{
|
{
|
||||||
id: 4,
|
id: 4,
|
||||||
title: "Web Dashboard Release",
|
title: "Web Dashboard Release",
|
||||||
timestamp: "2025-07-06T12:00:00Z",
|
timestamp: "2025-07-14T12:00:00Z",
|
||||||
author: Authors.ROCORD,
|
author: Authors.ROCORD,
|
||||||
summary: "Introducing the new LiteNet Web Dashboard",
|
summary: "Introducing the new LiteNet Web Dashboard",
|
||||||
content: `
|
content: `
|
||||||
|
|
Loading…
Reference in a new issue