mirror of
https://github.com/tinyhumansai/openhuman.git
synced 2026-07-29 14:02:19 +00:00
- Added .gitignore to exclude unnecessary files and directories. - Created ESLint configuration for code quality and consistency. - Set up Next.js configuration file for project settings. - Initialized package.json with dependencies and scripts for development. - Configured PostCSS for Tailwind CSS integration. - Added global styles and layout components for the landing page. - Implemented core components including AnimatedBackground, AnimatedLogo, and Feedback features. - Established feedback management system with modals and kanban board for user interactions. - Included README for project setup and usage instructions.
60 lines
1.3 KiB
TypeScript
60 lines
1.3 KiB
TypeScript
"use client";
|
|
|
|
import { useEffect } from "react";
|
|
import { useSearchParams } from "next/navigation";
|
|
|
|
const STORAGE_KEY = "global_token";
|
|
|
|
/**
|
|
* Gets the JWT token from localStorage.
|
|
* Returns null if token is not found or localStorage is unavailable.
|
|
*/
|
|
export function getAuthToken(): string | null {
|
|
if (typeof window === "undefined") {
|
|
return null;
|
|
}
|
|
try {
|
|
return localStorage.getItem(STORAGE_KEY);
|
|
} catch {
|
|
// Ignore storage errors (e.g. disabled cookies, private browsing)
|
|
return null;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Reads the bearer token from the current URL (?token=...) and
|
|
* persists it to localStorage for reuse across pages.
|
|
*
|
|
* Example URL:
|
|
* https://localhost:3000/pricing?token=${globalToken}
|
|
*/
|
|
export function useAuthToken() {
|
|
const searchParams = useSearchParams();
|
|
|
|
useEffect(() => {
|
|
const urlToken = searchParams.get("token");
|
|
|
|
if (urlToken) {
|
|
try {
|
|
localStorage.setItem(STORAGE_KEY, urlToken);
|
|
} catch {
|
|
// Ignore storage errors (e.g. disabled cookies)
|
|
}
|
|
return;
|
|
}
|
|
|
|
// Fallback: use previously stored token
|
|
try {
|
|
const stored = localStorage.getItem(STORAGE_KEY);
|
|
if (stored) {
|
|
}
|
|
} catch {
|
|
// Ignore storage errors
|
|
}
|
|
}, [searchParams]);
|
|
|
|
// Return the token for component use
|
|
return getAuthToken();
|
|
}
|
|
|