Skip to content

Commit

Permalink
Merge pull request #29089 from Expensify/hayata-pass-auth-token-to-em…
Browse files Browse the repository at this point in the history
…bedded-olddot

Set `authToken` and `email` cookies from NewDot
  • Loading branch information
robertjchen authored Oct 10, 2023
2 parents d916eff + a0e3fe1 commit f8ed016
Showing 1 changed file with 34 additions and 2 deletions.
36 changes: 34 additions & 2 deletions src/components/IFrame.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
/* eslint-disable es/no-nullish-coalescing-operators */
import React, {useEffect, useState} from 'react';
import {withOnyx} from 'react-native-onyx';
import PropTypes from 'prop-types';
import ONYXKEYS from '../ONYXKEYS';

function getNewDotURL(url) {
const urlObj = new URL(url);
Expand Down Expand Up @@ -50,6 +53,11 @@ function getOldDotURL(url) {
const pathname = urlObj.pathname;
const paths = pathname.slice(1).split('/');

// TODO: temporary measure until linking config is adjusted
if (pathname.startsWith('/r')) {
return 'inbox';
}

if (pathname === 'home') {
return 'inbox';
}
Expand Down Expand Up @@ -78,8 +86,19 @@ function getOldDotURL(url) {
return pathname;
}

export default function ReportScreen() {
const [oldDotURL, setOldDotURL] = useState('https://www.expensify.com.dev');
const propTypes = {
// The session of the logged in person
session: PropTypes.shape({
// The email of the logged in person
email: PropTypes.string,

// The authToken of the logged in person
authToken: PropTypes.string,
}).isRequired,
};

function OldDotIFrame({session}) {
const [oldDotURL, setOldDotURL] = useState('https://staging.expensify.com');

useEffect(() => {
setOldDotURL(`https://expensify.com.dev/${getOldDotURL(window.location.href)}`);
Expand All @@ -92,6 +111,11 @@ export default function ReportScreen() {
});
}, []);

useEffect(() => {
document.cookie = `authToken=${session.authToken}; domain=expensify.com.dev; path=/;`;
document.cookie = `email=${session.email}; domain=expensify.com.dev; path=/;`;
}, [session.authToken, session.email]);

return (
<iframe
style={{flex: 1}}
Expand All @@ -100,3 +124,11 @@ export default function ReportScreen() {
/>
);
}

OldDotIFrame.propTypes = propTypes;

export default withOnyx({
session: {
key: ONYXKEYS.SESSION,
},
})(OldDotIFrame);

0 comments on commit f8ed016

Please sign in to comment.