- // Use the token of the user we are getting data for. This avoids any admin/non-admin permissions
- // issues since a user will always be able to query the api server for their own user data.
- dispatch(saveApiToken(linkAccountData.token));
- const savedUserResource = await services.userService.get(linkAccountData.userUuid);
- dispatch(saveApiToken(curToken));
-
- let params: any;
- if (linkAccountData.type === LinkAccountType.ACCESS_OTHER_ACCOUNT) {
- params = {
- originatingUser: OriginatingUser.USER_TO_LINK,
- targetUser: curUserResource,
- targetUserToken: curToken,
- userToLink: savedUserResource,
- userToLinkToken: linkAccountData.token
- };
- }
- else if (linkAccountData.type === LinkAccountType.ADD_OTHER_LOGIN) {
- params = {
- originatingUser: OriginatingUser.TARGET_USER,
- targetUser: savedUserResource,
- targetUserToken: linkAccountData.token,
- userToLink: curUserResource,
- userToLinkToken: curToken
- };
- }
- else {
- // This should never really happen, but just in case, switch to the user that
- // originated the linking operation (i.e. the user saved in session data)
- dispatch(switchUser(savedUserResource, linkAccountData.token));
- dispatch(linkAccountPanelActions.LINK_INIT({targetUser: savedUserResource}));
- throw new Error("Invalid link account type.");
- }
+ // First check if an account link operation has completed
+ dispatch(checkForLinkStatus());
+
+ // Continue loading the link account panel
+ dispatch(setBreadcrumbs([{ label: 'Link account' }]));
+ const curUser = getState().auth.user;
+ const curToken = getState().auth.apiToken;
+ if (curUser && curToken) {
+
+ // If there is link account session data, then the user has logged in a second time
+ const linkAccountData = services.linkAccountService.getAccountToLink();
+ if (linkAccountData) {
+
+ dispatch(linkAccountPanelActions.SET_IS_PROCESSING({ isProcessing: true }));
+ const curUserResource = await services.userService.get(curUser.uuid);
+
+ // Use the token of the user we are getting data for. This avoids any admin/non-admin permissions
+ // issues since a user will always be able to query the api server for their own user data.
+ const svc = newServices(dispatch, linkAccountData.token);
+ const savedUserResource = await svc.userService.get(linkAccountData.userUuid);