use devise instead auth0
This commit is contained in:
@@ -8,7 +8,7 @@ export type AppContext = {
|
||||
|
||||
const Context = createContext<AppContext | null>(null);
|
||||
|
||||
export const useAppContext = (): AppContext => {
|
||||
export const useApp = (): AppContext => {
|
||||
const context = useContext(Context);
|
||||
|
||||
if (context === null) {
|
||||
@@ -18,7 +18,7 @@ export const useAppContext = (): AppContext => {
|
||||
return context;
|
||||
};
|
||||
|
||||
export const AppContext: FC = ({ children }) => {
|
||||
export const AppProvider: FC = ({ children }) => {
|
||||
const [sideNavExpanded, setSideNavExpanded] = useState(false);
|
||||
|
||||
return (
|
||||
@@ -1,24 +0,0 @@
|
||||
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
||||
import { Auth0Provider } from "@auth0/auth0-react";
|
||||
import type { FC } from "react";
|
||||
import React from "react";
|
||||
|
||||
export const AuthProvider: FC = ({ children }) => {
|
||||
// @ts-ignore
|
||||
const domain = window.AUTH_DOMAIN;
|
||||
// @ts-ignore
|
||||
const clientId = window.AUTH_CLIENT_ID;
|
||||
// @ts-ignore
|
||||
const audience = window.AUTH_AUDIENCE;
|
||||
|
||||
return (
|
||||
<Auth0Provider
|
||||
domain={domain}
|
||||
clientId={clientId}
|
||||
audience={audience}
|
||||
redirectUri={window.location.origin}
|
||||
>
|
||||
{children}
|
||||
</Auth0Provider>
|
||||
);
|
||||
};
|
||||
32
app/javascript/src/contexts/UserProvider.tsx
Normal file
32
app/javascript/src/contexts/UserProvider.tsx
Normal file
@@ -0,0 +1,32 @@
|
||||
import type { FC } from "react";
|
||||
import React, { createContext, useContext } from "react";
|
||||
|
||||
type CurrentUserContext = {
|
||||
user: {
|
||||
readonly firstName: string;
|
||||
} | null;
|
||||
isAuthenticated: boolean;
|
||||
};
|
||||
|
||||
const Context = createContext<CurrentUserContext>({
|
||||
user: null,
|
||||
isAuthenticated: false,
|
||||
});
|
||||
|
||||
export const useCurrentUser = (): CurrentUserContext => {
|
||||
const context = useContext(Context);
|
||||
|
||||
return context;
|
||||
};
|
||||
|
||||
type Props = {
|
||||
user: {
|
||||
readonly firstName: string;
|
||||
} | null;
|
||||
};
|
||||
|
||||
export const UserProvider: FC<Props> = ({ user, children }) => (
|
||||
<Context.Provider value={{ user, isAuthenticated: !!user }}>
|
||||
{children}
|
||||
</Context.Provider>
|
||||
);
|
||||
Reference in New Issue
Block a user