use devise instead auth0

This commit is contained in:
João Geonizeli
2021-08-09 22:07:48 -03:00
parent 15abf28e80
commit 645b818f6c
48 changed files with 519 additions and 399 deletions

View File

@@ -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 (

View File

@@ -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>
);
};

View 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>
);