This repository has been archived by the owner on Aug 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove files from commit that shouldn've have changed
- Loading branch information
1 parent
68d116e
commit 439bec3
Showing
7 changed files
with
137 additions
and
75 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,4 +6,4 @@ dist-ssr | |
|
||
.env | ||
# Local Netlify folder | ||
.netlify | ||
.netlify |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,41 @@ | ||
import getProxyUrl from '@src/utils/getProxyUrl'; | ||
import { useMemo, useState, useEffect } from 'react'; | ||
import { useLocation } from 'react-router-dom'; | ||
import { useState, useEffect, useCallback } from 'react'; | ||
|
||
import fetch from '../utils/fetch'; | ||
|
||
const useToken = () => { | ||
const location = useLocation(); | ||
const [error, setError] = useState<string | undefined>(); | ||
|
||
const accessToken = useMemo(() => { | ||
return encodeURIComponent( | ||
new URLSearchParams(window.location.search).get('token') || import.meta.env.VITE_CLIENT_ACCESS_TOKEN || '', | ||
); | ||
}, [location]); | ||
const accessToken = import.meta.env.VITE_CLIENT_ACCESS_TOKEN || ''; | ||
|
||
const [YOUR_TOKEN, setToken] = useState<string | null>(null); | ||
|
||
const getToken = async () => { | ||
const getToken = useCallback(async () => { | ||
if (accessToken && accessToken.length) { | ||
return accessToken; | ||
} | ||
const res = await fetch(`${getProxyUrl()}/client-access-token`, { method: 'GET' }); | ||
return res.data.access_token; | ||
}; | ||
try { | ||
const res = await fetch(`${getProxyUrl()}/client-access-token`); | ||
|
||
if (!res.data.access_token) { | ||
setError(`Invalid Dolby.io token, please refer to Readme to set it correctly`); | ||
} else { | ||
setError(undefined); | ||
} | ||
return res.data.access_token; | ||
} catch (e) { | ||
setError(`Invalid Dolby.io token, please refer to Readme to set it correctly`); | ||
return null; | ||
} | ||
}, [accessToken]); | ||
|
||
useEffect(() => { | ||
(async () => { | ||
setToken(await getToken()); | ||
})(); | ||
}, []); | ||
}, [getToken]); | ||
|
||
return { YOUR_TOKEN, getToken }; | ||
return { YOUR_TOKEN, getToken, error }; | ||
}; | ||
|
||
export default useToken; |
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
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
Oops, something went wrong.