Overview

hit is a helper function as a wrapper for the fetch function in the browser. The benefit of using this is that it will automatically handle unauthenticated responses by fetching a new access token using the refresh token.

How to Use

All the parameters are the same as the native fetch function. Here's an example of how to use it:

ts

import { hit } from '@/lib/web/hit' const resp = await hit('/api/demo', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ key: 'value' }) }) const json = await resp.json()

āœ… It will automatically include the credentials: 'include' option to send cookies for authentication.