fix: use cookie token from sso if applicable
@@ -4,6 +4,7 @@ import Auth, { AUTH_COOKIE_KEY } from 'contexts/Auth';
import handleError, { ErrorType } from 'ErrorHandler';
import { globalStorage } from 'globalStorage';
import { getCurrentUser, isAuthFailure } from 'services/api';
+import { updateDetApi } from 'services/apiConfig';
import { isAborted } from 'services/utils';
import { getCookie } from 'utils/browser';
@@ -17,7 +18,21 @@ const useAuthCheck = (): (() => void) => {
useEffect(() => {
const checkAuth = async (signal: AbortSignal): Promise<void> => {
- const authToken = getCookie(AUTH_COOKIE_KEY) || globalStorage.authToken;
+ /*
+ * Check for an auth token in the cookie from SSO and
+ * update the storage token and the api to use the cookie token.
+ */
+ const cookieToken = getCookie(AUTH_COOKIE_KEY);
+ if (cookieToken) {
+ globalStorage.authToken = cookieToken;
+ updateDetApi({ apiKey: 'Bearer ' + cookieToken });
+ }
+
+ /*
+ * If a cookie token is not found, use the storage token if applicable.
+ * Proceed to verify user only if there is an auth token.
+ */
+ const authToken = globalStorage.authToken;
if (!authToken) {
setAuth({ type: Auth.ActionType.MarkChecked });
return;
