mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-04-25 16:56:22 +02:00
refactor: centralize authentication handling
- Replaced direct localStorage token access with a centralized `getBearerToken` function across various components and hooks to improve code maintainability and security. - Updated API calls to use `authenticatedFetch` for consistent authentication handling. - Enhanced user experience by ensuring proper redirection to login when authentication fails. - Cleaned up unused imports and improved overall code structure for better readability.
This commit is contained in:
parent
6cc9e38e1d
commit
b2a97b39ce
35 changed files with 396 additions and 497 deletions
|
|
@ -27,6 +27,7 @@ import {
|
|||
CardTitle,
|
||||
} from "@/components/ui/card";
|
||||
import { useInviteInfo } from "@/hooks/use-rbac";
|
||||
import { getBearerToken } from "@/lib/auth-utils";
|
||||
|
||||
export default function InviteAcceptPage() {
|
||||
const params = useParams();
|
||||
|
|
@ -47,7 +48,7 @@ export default function InviteAcceptPage() {
|
|||
// Check if user is logged in
|
||||
useEffect(() => {
|
||||
if (typeof window !== "undefined") {
|
||||
const token = localStorage.getItem("surfsense_bearer_token");
|
||||
const token = getBearerToken();
|
||||
setIsLoggedIn(!!token);
|
||||
}
|
||||
}, []);
|
||||
|
|
@ -71,7 +72,10 @@ export default function InviteAcceptPage() {
|
|||
const handleLoginRedirect = () => {
|
||||
// Store the invite code to redirect back after login
|
||||
localStorage.setItem("pending_invite_code", inviteCode);
|
||||
router.push("/auth");
|
||||
// Save the current invite page URL so we can return after authentication
|
||||
localStorage.setItem("surfsense_redirect_path", `/invite/${inviteCode}`);
|
||||
// Redirect to login (we manually set the path above since invite pages need special handling)
|
||||
window.location.href = "/login";
|
||||
};
|
||||
|
||||
// Check for pending invite after login
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue