How to handle dependent Firebase token data #507
-
I use Firebase Auth. An Unhandled Runtime Error occurred. What's the ideal way to do it? What should I do if I want to use SWR?
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
I would call that method inside the fetcher, and throw an error if the user is not logged in (doesn't has the token) |
Beta Was this translation helpful? Give feedback.
-
Hi, I am facing the same problem with Auth0 access tokens Hereafter my custom hook: import useSWR from "swr";
import {useAuth0} from "@auth0/auth0-react";
export default async function useBooks () {
const { getAccessTokenSilently } = useAuth0();
const accessToken = await getAccessTokenSilently();
const { data, error } = useSWR(['/books', accessToken]);
return {
books: data,
isLoading: !error && !data,
isError: error
}
} The problem is that, when I call this hook from my functional component (
The error makes sense as the function |
Beta Was this translation helpful? Give feedback.
I would call that method inside the fetcher, and throw an error if the user is not logged in (doesn't has the token)