persistent login now works, no more cookie errors
This commit is contained in:
parent
a7b417abdf
commit
47e3939112
5 changed files with 16 additions and 25 deletions
|
|
@ -6,7 +6,7 @@ import { Auth0Provider } from '@auth0/auth0-react'
|
||||||
import { or } from '../utils/types'
|
import { or } from '../utils/types'
|
||||||
import AuthWrapper from '../providers/auth'
|
import AuthWrapper from '../providers/auth'
|
||||||
import HTTPProvider from '../providers/http'
|
import HTTPProvider from '../providers/http'
|
||||||
import { useUserAPI } from '../providers/pond/userAPI'
|
// import { useUserAPI } from '../providers/pond/userAPI'
|
||||||
// import LoginButton from '../providers/LoginButton'
|
// import LoginButton from '../providers/LoginButton'
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
|
|
@ -26,7 +26,7 @@ function App() {
|
||||||
let client_id = import.meta.env.VITE_AUTH0_BXT_CLIENT_ID;
|
let client_id = import.meta.env.VITE_AUTH0_BXT_CLIENT_ID;
|
||||||
|
|
||||||
console.log(url)
|
console.log(url)
|
||||||
console.log(audience)
|
// console.log(audience)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Auth0Provider
|
<Auth0Provider
|
||||||
|
|
@ -36,6 +36,8 @@ function App() {
|
||||||
audience: or(audience, ""),
|
audience: or(audience, ""),
|
||||||
redirect_uri: window.location.origin + "/callback"
|
redirect_uri: window.location.origin + "/callback"
|
||||||
}}
|
}}
|
||||||
|
useRefreshTokens={true}
|
||||||
|
cacheLocation='localstorage'
|
||||||
>
|
>
|
||||||
<AuthWrapper>
|
<AuthWrapper>
|
||||||
<HTTPProvider>
|
<HTTPProvider>
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
import React from 'react';
|
|
||||||
import { useAuth0 } from '@auth0/auth0-react';
|
import { useAuth0 } from '@auth0/auth0-react';
|
||||||
|
|
||||||
const LoginButton = () => {
|
const LoginButton = () => {
|
||||||
|
|
|
||||||
|
|
@ -6,25 +6,19 @@ export default function AuthWrapper(props: PropsWithChildren<{}>) {
|
||||||
const { children } = props;
|
const { children } = props;
|
||||||
const { isLoading, loginWithRedirect, isAuthenticated, user } = useAuth0();
|
const { isLoading, loginWithRedirect, isAuthenticated, user } = useAuth0();
|
||||||
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
// console.log("Authenticated: ", isAuthenticated)
|
||||||
|
// console.log("Loading: ", isLoading)
|
||||||
if (!isAuthenticated && !isLoading) {
|
if (!isAuthenticated && !isLoading) {
|
||||||
loginWithRedirect();
|
loginWithRedirect();
|
||||||
}
|
}
|
||||||
}, [isAuthenticated, loginWithRedirect]);
|
}, [isAuthenticated, loginWithRedirect, isLoading]);
|
||||||
|
|
||||||
useEffect(() => {
|
if (isAuthenticated) return (
|
||||||
console.log(user)
|
children
|
||||||
console.log(user?.sub)
|
)
|
||||||
console.log(user?.picture)
|
|
||||||
|
|
||||||
}, [user])
|
return (
|
||||||
|
<p>Redirecting...</p>
|
||||||
|
)
|
||||||
|
|
||||||
// if (isAuthenticated) return (
|
|
||||||
// children
|
|
||||||
// )
|
|
||||||
|
|
||||||
return (children)
|
|
||||||
}
|
}
|
||||||
|
|
@ -33,14 +33,10 @@ export default function HTTPProvider(props: PropsWithChildren<any>) {
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isAuthenticated) getAccessTokenSilently().then(t => {
|
if (isAuthenticated) getAccessTokenSilently().then(t => {
|
||||||
setToken(t)
|
setToken(t)
|
||||||
})
|
})
|
||||||
}, [setToken, isAuthenticated])
|
}, [setToken, isAuthenticated])
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
console.log(token)
|
|
||||||
}, [token])
|
|
||||||
|
|
||||||
const defaultOptions = (demo: boolean = false) => {
|
const defaultOptions = (demo: boolean = false) => {
|
||||||
if (demo || !isAuthenticated || !token) {
|
if (demo || !isAuthenticated || !token) {
|
||||||
return {
|
return {
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ import { createContext, PropsWithChildren, useContext } from "react";
|
||||||
// import { objectQueryParams, pondURL } from "./pond";
|
// import { objectQueryParams, pondURL } from "./pond";
|
||||||
// import { or } from "utils";
|
// import { or } from "utils";
|
||||||
// import { useGlobalState } from "providers";
|
// import { useGlobalState } from "providers";
|
||||||
import { AxiosResponse } from "axios";
|
// import { AxiosResponse } from "axios";
|
||||||
import { useHTTP } from "../http";
|
import { useHTTP } from "../http";
|
||||||
import { pondURL } from "./pond";
|
import { pondURL } from "./pond";
|
||||||
|
|
||||||
|
|
@ -50,7 +50,7 @@ export const UserAPIContext = createContext<IUserAPIContext>({} as IUserAPIConte
|
||||||
|
|
||||||
export default function UserProvider(props: PropsWithChildren<any>) {
|
export default function UserProvider(props: PropsWithChildren<any>) {
|
||||||
const { children } = props;
|
const { children } = props;
|
||||||
const { get, put } = useHTTP();
|
const { get, /*put*/ } = useHTTP();
|
||||||
// const [{ as }] = useGlobalState();
|
// const [{ as }] = useGlobalState();
|
||||||
|
|
||||||
// const listUsers = (
|
// const listUsers = (
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue