-
Notifications
You must be signed in to change notification settings - Fork 179
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update a custom hook to get accessToken
- Loading branch information
Showing
5 changed files
with
37 additions
and
56 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
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './useApiCall' | ||
export * from './useGetAccessToken' |
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
26 changes: 26 additions & 0 deletions
26
opentrons-ai-client/src/resources/hooks/useGetAccessToken.ts
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { useAuth0 } from '@auth0/auth0-react' | ||
|
||
interface UseGetAccessTokenResult { | ||
getAccessToken: () => Promise<string> | ||
} | ||
|
||
const audience = 'sandbox-ai-api' | ||
export const useGetAccessToken = (): UseGetAccessTokenResult => { | ||
const { getAccessTokenSilently } = useAuth0() | ||
|
||
const getAccessToken = async (): Promise<string> => { | ||
try { | ||
const accessToken = await getAccessTokenSilently({ | ||
authorizationParams: { | ||
audience, | ||
}, | ||
}) | ||
return accessToken | ||
} catch (error) { | ||
console.error('Error getting access token:', error) | ||
throw error | ||
} | ||
} | ||
|
||
return { getAccessToken } | ||
} |
17 changes: 0 additions & 17 deletions
17
opentrons-ai-client/src/resources/hooks/useGetAuth0Token.ts
This file was deleted.
Oops, something went wrong.