Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set authToken and email cookies from NewDot #29089

Merged
merged 3 commits into from
Oct 10, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 35 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=/;`;
Comment on lines +115 to +116
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if it's worth but maybe we can early return when either of authToken or email doesn't exist?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think there is a situation when these values are not defined because IFrame component is displayed only if the user is logged in 🤔

or do you think we're missing any exceptions to this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok it's fine if no case

}, [session.authToken, session.email]);

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

OldDotIFrame.propTypes = propTypes;

export default withOnyx({
session: {
key: ONYXKEYS.SESSION,
selector: (session) => session,
hayata-suenaga marked this conversation as resolved.
Show resolved Hide resolved
},
})(OldDotIFrame);
Loading