useGetToken

Overview

Custom hook that provides a function to get JWT token for the logged in account. If a valid token is in the cache this will be returned, otherwise a request for a new token will be sent.

If a logged in account is not available, there will be a redirect to the Microsoft login page.

As this uses msal caching functionality, it can be called on every API request without affecting performance.

Example : Default usage
import { useGetToken } from '@ska-telescope/ska-login-page';

...

const getToken = useGetToken();

...

const accessToken = await getToken({ scopes: ['user:read'] });