diff --git a/src/index.tsx b/src/index.tsx index 322c16b..75f4c1d 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -72,7 +72,7 @@ export const useIdentityContext = _useIdentityContext; // we dont want to expose export function IdentityContextProvider({ url, children, - onAuthChange = () => {}, + onAuthChange = () => { }, }: { url: string; children: React.ReactNode; @@ -83,8 +83,8 @@ export function IdentityContextProvider({ // just a safety check in case a JS user tries to skip this throw new Error( 'invalid netlify instance URL: ' + - url + - '. Please check the docs for proper usage or file an issue.' + url + + '. Please check the docs for proper usage or file an issue.' ); } const identity = React.useMemo(() => useNetlifyIdentity(url, onAuthChange), [ @@ -99,7 +99,7 @@ export function IdentityContextProvider({ /** some people may want to use this as a hook and bring their own contexts */ export function useNetlifyIdentity( url: string, - onAuthChange: authChangeParam = () => {} + onAuthChange: authChangeParam = () => { } ): ReactNetlifyIdentityAPI { const goTrueInstance = new GoTrue({ APIUrl: `${url}/.netlify/identity`, @@ -115,10 +115,6 @@ export function useNetlifyIdentity( return _user; // so that we can continue chaining }; - React.useEffect(() => { - runRoutes(goTrueInstance, _setUser); - }, []); - /******* OPERATIONS */ // make sure the Registration preferences under Identity settings in your Netlify dashboard are set to Open. // https://react-netlify-identity.netlify.com/login#access_token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1NTY0ODY3MjEsInN1YiI6ImNiZjY5MTZlLTNlZGYtNGFkNS1iOTYzLTQ4ZTY2NDcyMDkxNyIsImVtYWlsIjoic2hhd250aGUxQGdtYWlsLmNvbSIsImFwcF9tZXRhZGF0YSI6eyJwcm92aWRlciI6ImdpdGh1YiJ9LCJ1c2VyX21ldGFkYXRhIjp7ImF2YXRhcl91cmwiOiJodHRwczovL2F2YXRhcnMxLmdpdGh1YnVzZXJjb250ZW50LmNvbS91LzY3NjQ5NTc_dj00IiwiZnVsbF9uYW1lIjoic3d5eCJ9fQ.E8RrnuCcqq-mLi1_Q5WHJ-9THIdQ3ha1mePBKGhudM0&expires_in=3600&refresh_token=OyA_EdRc7WOIVhY7RiRw5w&token_type=bearer diff --git a/src/runRoutes.tsx b/src/runRoutes.tsx deleted file mode 100644 index e7c6e7d..0000000 --- a/src/runRoutes.tsx +++ /dev/null @@ -1,63 +0,0 @@ -import GoTrue, { User } from 'gotrue-js'; - -/** - * This code runs on every rerender so keep it light - * keep checking the current route and do logic based on the route - * as dictated by netlify identity's communication with us via hashes - */ - -const routes = /(confirmation|invite|recovery|email_change)_token=([^&]+)/; -const errorRoute = /error=access_denied&error_description=403/; -const accessTokenRoute = /access_token=/; -const confirmationRoute = /confirmation_token=/; - -export function runRoutes( - gotrue: GoTrue, - setUser: (value: User) => User | undefined, - remember = true -) { - const hash = (document.location.hash || '').replace(/^#\/?/, ''); - if (!hash) return; // early terminate if no hash - - const m = hash.match(routes); - if (m) { - // store.verifyToken(m[1], m[2]); - document.location.hash = ''; - } - - const em = hash.match(errorRoute); - if (em) { - // store.openModal("signup"); - document.location.hash = ''; - } - const params = {} as { [key: string]: string }; - hash.split('&').forEach(pair => { - const [key, value] = pair.split('='); - params[key] = value; - }); - - const am = hash.match(accessTokenRoute); - if (am) { - if (!!document && params['access_token']) { - document.cookie = `nf_jwt=${params['access_token']}`; - } - document.location.hash = ''; - // store.openModal("login"); - // store.completeExternalLogin(params); - gotrue - .createUser(params, remember) - .then(setUser) - .catch(console.error); - } - - const cm = hash.match(confirmationRoute); - if (cm) { - document.location.hash = ''; - // store.openModal("login"); - // store.completeExternalLogin(params); - gotrue - .confirm(params['confirmation_token']) - .then(setUser) - .catch(console.error); - } -}