mirror of
https://github.com/NginxProxyManager/nginx-proxy-manager.git
synced 2025-07-04 00:46:50 +00:00
Oauth2 support
This commit is contained in:
@ -1,7 +1,8 @@
|
||||
import { lazy, Suspense } from "react";
|
||||
|
||||
import { BrowserRouter, Routes, Route } from "react-router-dom";
|
||||
import { BrowserRouter, Route, Routes } from "react-router-dom";
|
||||
|
||||
import { TokenResponse } from "src/api/npm";
|
||||
import { SiteWrapper, SpinnerPage, Unhealthy } from "src/components";
|
||||
import { useAuthState, useLocaleState } from "src/context";
|
||||
import { useHealth } from "src/hooks";
|
||||
@ -24,10 +25,21 @@ const Users = lazy(() => import("src/pages/Users"));
|
||||
|
||||
function Router() {
|
||||
const health = useHealth();
|
||||
const { authenticated } = useAuthState();
|
||||
const { authenticated, handleTokenUpdate } = useAuthState();
|
||||
const { locale } = useLocaleState();
|
||||
const Spinner = <SpinnerPage />;
|
||||
|
||||
// Load token from URL Query Params
|
||||
const searchParams = new URLSearchParams(document.location.search);
|
||||
const t = searchParams.get("token_response");
|
||||
if (t) {
|
||||
const tokenResponse: TokenResponse = JSON.parse(t);
|
||||
handleTokenUpdate(tokenResponse);
|
||||
window.location.href = "/";
|
||||
return;
|
||||
}
|
||||
// End Load token from URL Query Params
|
||||
|
||||
if (health.isLoading) {
|
||||
return Spinner;
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { useEffect, ReactNode } from "react";
|
||||
import { ReactNode, useEffect } from "react";
|
||||
|
||||
import { Box, Container, useToast } from "@chakra-ui/react";
|
||||
import { useQueryClient } from "@tanstack/react-query";
|
||||
|
@ -9,6 +9,7 @@ import AuthStore from "src/modules/AuthStore";
|
||||
// Context
|
||||
export interface AuthContextType {
|
||||
authenticated: boolean;
|
||||
handleTokenUpdate: (response: TokenResponse) => void;
|
||||
login: (type: string, username: string, password: string) => Promise<void>;
|
||||
logout: () => void;
|
||||
token?: string;
|
||||
@ -62,7 +63,7 @@ function AuthProvider({
|
||||
true,
|
||||
);
|
||||
|
||||
const value = { authenticated, login, logout };
|
||||
const value = { authenticated, login, logout, handleTokenUpdate };
|
||||
|
||||
return <AuthContext.Provider value={value}>{children}</AuthContext.Provider>;
|
||||
}
|
||||
|
Reference in New Issue
Block a user