2017-05-26 17:11:33 -05:00
|
|
|
/* @flow */
|
|
|
|
|
|
2020-05-07 17:26:37 -05:00
|
|
|
import { parseURLParams } from '../util';
|
2017-05-26 17:11:33 -05:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Retrieves the JSON Web Token (JWT), if any, defined by a specific
|
|
|
|
|
* {@link URL}.
|
|
|
|
|
*
|
|
|
|
|
* @param {URL} url - The {@code URL} to parse and retrieve the JSON Web Token
|
|
|
|
|
* (JWT), if any, from.
|
|
|
|
|
* @returns {string} The JSON Web Token (JWT), if any, defined by the specified
|
|
|
|
|
* {@code url}; otherwise, {@code undefined}.
|
|
|
|
|
*/
|
|
|
|
|
export function parseJWTFromURLParams(url: URL = window.location) {
|
|
|
|
|
return parseURLParams(url, true, 'search').jwt;
|
|
|
|
|
}
|
2020-10-26 13:53:44 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the user name after decoding the jwt.
|
|
|
|
|
*
|
|
|
|
|
* @param {Object} state - The app state.
|
|
|
|
|
* @returns {string}
|
|
|
|
|
*/
|
|
|
|
|
export function getJwtName(state: Object) {
|
2020-11-05 11:35:03 -06:00
|
|
|
const { user } = state['features/base/jwt'];
|
2020-10-26 13:53:44 +02:00
|
|
|
|
2020-11-05 11:35:03 -06:00
|
|
|
return user?.name || '';
|
2020-10-26 13:53:44 +02:00
|
|
|
}
|