I was new to auth0, when I tried to experiment with auth0's parseHash. It surprised me that somehow this function returns null. I tried to take a peep inside the source code, it seems this function attempts to return something eventually.
Here's the part of code that confused me:
import React from 'react';
import { Link } from '@reach/router';
import './Callback.sass';
export const Callback = ({ auth, navigate }) => {
let result = auth.parseHash((err, authResult) => {
if (err) {
return (
<div className="error">
<h1>{err.error}</h1>
<p>{err.errorDescription}</p>
<Link to="/">Home</Link>
</div>
);
} else {
console.log({ authResult });
return 'profile';
// localStorage.setItem('authResult', JSON.stringify(authResult));
// navigate('/profile');
}
});
console.log({ result });
if (result) return result;
return <React.Fragment />;
};
Which I think is really confusing. The console logs 'authResult' part, yet the result
is undefined
. (I even tested with async await, still can't get what I expect).
I am currently just wrap the result to work around this.
Is this a bug? Or am I using this method not in a correct way?