Skip to content

Commit

Permalink
fix(react): add success to useVerifyToken
Browse files Browse the repository at this point in the history
  • Loading branch information
jrea committed Jan 25, 2023
1 parent 5178f12 commit 38853a4
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions packages/react/src/lib/hooks/useVerifyToken/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import { useNile } from '../../../context';
* A function to handle removing the `state` query param on login, in exchange for a cookie that can be used for authentication
* @returns an error, if there is one
*/
export const useVerifyToken = (): null | string => {
export const useVerifyToken = (): [boolean, null | string] => {
const nile = useNile();
const [token, setToken] = React.useState<null | string>(null);
const [error, setError] = React.useState<null | string>(null);
const [success, setSuccess] = React.useState(false);
const url = React.useMemo(() => {
return new URL(window.location.href);
}, []);
Expand All @@ -36,6 +37,7 @@ export const useVerifyToken = (): null | string => {
await fetch(
`${nile.config?.basePath}/auth/oidc/verify?state=${token}`
);
setSuccess(true);
} catch (e) {
if (e instanceof Error) {
setError(e.message);
Expand All @@ -46,5 +48,5 @@ export const useVerifyToken = (): null | string => {
doRequest();
}, [nile.config?.basePath, token, url]);

return error;
return [success, error];
};

0 comments on commit 38853a4

Please sign in to comment.