You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

functions.js 821B

123456789101112131415161718192021222324252627282930
  1. /* @flow */
  2. import jwtDecode from 'jwt-decode';
  3. import { parseURLParams } from '../util';
  4. /**
  5. * Retrieves the JSON Web Token (JWT), if any, defined by a specific
  6. * {@link URL}.
  7. *
  8. * @param {URL} url - The {@code URL} to parse and retrieve the JSON Web Token
  9. * (JWT), if any, from.
  10. * @returns {string} The JSON Web Token (JWT), if any, defined by the specified
  11. * {@code url}; otherwise, {@code undefined}.
  12. */
  13. export function parseJWTFromURLParams(url: URL = window.location) {
  14. return parseURLParams(url, true, 'search').jwt;
  15. }
  16. /**
  17. * Returns the user name after decoding the jwt.
  18. *
  19. * @param {Object} state - The app state.
  20. * @returns {string}
  21. */
  22. export function getJwtName(state: Object) {
  23. const jwtData = jwtDecode(state['features/base/jwt'].jwt);
  24. return jwtData?.context?.user?.name || '';
  25. }