Last active
May 12, 2021 14:44
-
-
Save banagale/d632e1b37dd892b49fd1e33187dee51f to your computer and use it in GitHub Desktop.
Example custom hook for retrieving an OpenVidu session token, implemented using React Query
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Cookies from "js-cookie"; | |
import { wvApiUrl } from "../../routes"; | |
const fetchUrl = wvApiUrl.ovToken(); | |
export async function useCreateSessionToken(bodyData) { | |
const response = await fetch(fetchUrl, { | |
method: 'POST', | |
body: JSON.stringify(bodyData), | |
headers: { | |
"Content-type": "application/json", | |
"X-CSRFToken": Cookies.get('csrftoken') | |
} | |
}); | |
return await response.json(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment