|
1 |
| -// Copyright (c) 2020-2022 The MathWorks, Inc. |
| 1 | +// Copyright 2020-2022 The MathWorks, Inc. |
2 | 2 |
|
3 | 3 | import React, { useState, useCallback, useEffect, useMemo } from 'react';
|
4 | 4 | import { useSelector, useDispatch } from 'react-redux';
|
@@ -62,6 +62,11 @@ function App() {
|
62 | 62 | return url.split(window.location.origin)[1].split('index.html')[0]
|
63 | 63 | }, [])
|
64 | 64 |
|
| 65 | + const parseQueryParams = (url) => { |
| 66 | + const queryParams = new URLSearchParams(url.search); |
| 67 | + return queryParams; |
| 68 | + } |
| 69 | + |
65 | 70 | const toggleOverlayVisible = useCallback(
|
66 | 71 | () => dispatch(setOverlayVisibility(!overlayVisible)),
|
67 | 72 | [overlayVisible, dispatch]
|
@@ -142,18 +147,14 @@ function App() {
|
142 | 147 | }, [loadUrl]);
|
143 | 148 |
|
144 | 149 | useEffect(() => {
|
145 |
| - const url = document.URL; |
146 |
| - |
147 |
| - if(url.includes("?mwi_auth_token=")){ |
148 |
| - var token = url.split("?mwi_auth_token=")[1]; |
149 |
| - |
150 |
| - if(token){ |
151 |
| - dispatch(updateAuthStatus(token)) |
152 |
| - } |
153 |
| - window.history.replaceState(null, '', `${baseUrl}index.html`); |
154 |
| - } |
155 |
| - } |
156 |
| - , [dispatch, baseUrl]); |
| 150 | + const queryParams = parseQueryParams(window.location); |
| 151 | + const token = queryParams.get("mwi_auth_token"); |
| 152 | + |
| 153 | + if(token){ |
| 154 | + dispatch(updateAuthStatus(token)); |
| 155 | + } |
| 156 | + window.history.replaceState(null, '', `${baseUrl}index.html`); |
| 157 | + }, [dispatch, baseUrl]); |
157 | 158 |
|
158 | 159 | // Display one of:
|
159 | 160 | // * Confirmation
|
|
0 commit comments