Is there a way to reactivate Cognito tokens that are originating from a different tab?

I have a unique feature that opens a new tab on a different domain, and I want to ensure the cognito session remains active. To achieve this, I've implemented a hidden iframe with the same origin to transfer local storage data using the following code snippet:

const proxy = document.getElementById('proxyDashboard');
if (this.isIFrame(proxy) && proxy.contentWindow) {
  Object.keys(localStorage).forEach(function(key){
    proxy.contentWindow.postMessage(JSON.stringify({key, value: localStorage.getItem(key)}), 'http://localhost:4200');
  });
  console.log(this.dashboardUrl);
  window.open(this.dashboardUrl, '_blank');
}

On the receiving end, I'm retrieving the tokens like so:

constructor(){
  if (window.addEventListener) {
    window.addEventListener('message', this.receiveMessage.bind(this), false);
  } else {
    (<any>window).attachEvent('onmessage', this.receiveMessage.bind(this));
  }
}

receiveMessage: any = (event: any) =>  {
  if (event.origin !== 'http://localhost:4201') {
    return;
  }
  const payload = JSON.parse(event.data);
  localStorage.setItem(payload.key, JSON.stringify(payload.value));
}

The challenge now lies in reinstating the Cognito session. It seems that an extra step is required for Amplify or Cognito to recognize the newly transferred tokens.

Here's the current list of items in storage: https://i.sstatic.net/PM0cI.png

Thank you

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Incorporate personalized elements into your @react-three/fiber environment

My dilemma lies in the fact that I am trying to incorporate my custom components into my scene. However, these custom components are defined in a separate file. When I attempt to define my custom component, I encounter an error message stating: Cannot find ...

Using Typescript generics to deduce the type from the second parameter for utilization in the first slot

Here is the code snippet I'm working with: export type Subscribe<T extends object> = <U>( listener: (slice: U) => void, selector: (state: T) => U, ) => void // The actual implementation is not relevant const subscribe = {} as ...

Exploring the filter method in arrays to selectively print specific values of an object

const array = [ { value: "Value one", label: "Value at one" }, { value: "Value 2", label: "Value at 2" }, { value: "" , label: "Value at 3" } ...

Exploring nested contexts in react testing library with renderHook

This is a sample code snippet in TypeScript that uses React and Testing Library: import React, { FC, useEffect, useMemo, useState } from 'react'; import { renderHook, waitFor } from '@testing-library/react'; interface PropsCtx { inpu ...

Sending data using the x-www-form-urlencoded format from a Firebase cloud function

I'm attempting to send an API request to the Stripe API from a cloud firebase function using an HTTP POST method. The parameters required must be in a format known as 'x-www-form-urlencoded'. const httpOptions = { headers: new ...

Is there a way to showcase the contents of the angular "tags" object seamlessly?

Is there a way to show the content of the "tags" object using angular? I attempted to achieve it using {{gallery.tags.tag}} but unfortunately, it did not work import {IPhoto} from "./iphoto"; export interface IGallery { galleryId: string; title: ...

Ways to inform websocket client of authentication failure

Utilizing the (ws package) in Node.js to handle websockets, I leverage the "on upgrade" event to authenticate incoming clients based on a token provided as a URL parameter. Following the guide here, if the token is invalid/missing/expired, I utilize the fo ...

Is there a way to make an angular component reuse itself within its own code?

I am dealing with a parent and child component scenario where I need to pass data from the parent component to the child component. The aim is to display parentData.name in the child component when parentData.isFolder===false, and if parentData.isFolder=== ...

Tips for sending data to CSS in Angular

I have an Angular application where I need to calculate the width of an element and store it in a variable called finalposition. Then, I want to move this element to the left by (finalposition)px when hovering over it. How can I achieve this styling effect ...

Utilizando Typescript com Ionic 2 e AngularJS para autenticar através de um método de post na requisição HTTP e

Greetings and good afternoon to everyone. I hope you all are doing well. I am a beginner in AngularJS, currently using Visual Studio, Ionic 2, and TypeScript. I have successfully connected my app to a REST API in .NET and have implemented a token for tes ...

How to implement an instance method within a Typescript class for a Node.js application

I am encountering an issue with a callback function in my Typescript project. The problem arises when I try to implement the same functionality in a Node project using Typescript. It seems that when referencing 'this' in Node, it no longer points ...

Substitute all instances of null bytes

I need to remove null bytes from a string. However, after replacing the null bytes \u0000 in the string let data = {"tet":HelloWorld.\u0000\u0000\u0000\u0000"} let test = JSON.parse(data).tet.replace("\u0000", ""); I always ...

Instead of returning an object, the underscore groupBy function now returns an array

Currently, I am attempting to utilize underscore to create an array of entities that are grouped by their respective locations. The current format of the array consists of pairs in this structure { location: Location, data: T}[]. However, I aim to rearran ...

Saving the contents of a book in an Ionic mobile application

I'm working on an app that features an e-reader function for users to read a single book. Where should I save the text data for the book? I experimented with storing pages as .json files in the assets folder but ran into issues. The path to the asset ...

Angular - Showing validation messages post successful execution of two functions

I have encountered an issue with my form submission process involving two functions. When both functions succeed, I want to display a successful validation message. However, currently the success message is displayed even if the second function fails. How ...

Styling can be compromised by Angular due to selector element interference

I have a question regarding a bootstrap button group. The buttons within it are Angular components structured like this: <div class="btn-group float-right" role="group" aria-label="Basic example"> <app-action [actionType]="'inv ...

Angular 8 fails to retain data upon page refresh

I have a property called "isAdmin" which is a boolean. It determines whether the user is logged in as an admin or a regular user. I'm using .net core 2.2 for the backend and Postgre for the database. Everything works fine, but when I refresh the page, ...

Why does the property of {{hero.name}} function properly in a <h> tag but not in an <img> tag?

Within this template, the code below functions correctly: <h3>{{hero.name}}</h3> It also works for: <a routerLink="/details/{{hero.id}}">{{hero.name}}</a> However, there seems to be an issue with the following image path ...

Problem with moving functions from one file to another file via export and import

I currently have the following file structure: ---utilities -----index.ts -----tools.ts allfunctions.ts Within the tools.ts file, I have defined several functions that I export using export const. One of them is the helloWorld function: export const hel ...

Is the parent component not triggering the function properly?

Hey there, I'm working with the code snippet below in this component: <app-steps #appSteps [menuSteps]="steps" [currentComponent]="outlet?.component" (currentStepChange)="currentStep = $event"> <div appStep ...