useAsyncToken
Platforms:✓ Web✓ React Native✓ Expo
If you want to send authenticated request, you can get the required tokens from useAuthState().
- If a fresh token is optional, you can simply get the current id token from
useToken(). - If you must have a fresh token, request one from
useAsyncToken().
import { useAuth } from '@healthblocks-io/core/auth'
function Page() {
// Read current token data
const id_token = useToken()
const submit = () =>
fetch('/api', { headers: { Authorization: 'Bearer ' + id_token } })
// Callback that will refresh the token if needed => better
const token = useAsyncToken()
const submit = async () =>
fetch('/api', { headers: { Authorization: 'Bearer ' + (await token()) } })
}