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

fix(amazon-cognito-identity-js): specify the correct userAgent/deviceName when remembering devices (React Native) #10724

Merged
Merged
Show file tree
Hide file tree
Changes from 3 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
7 changes: 5 additions & 2 deletions packages/amazon-cognito-identity-js/src/CognitoUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,11 @@ import StorageHelper from './StorageHelper';
* @param {bool=} userConfirmationNecessary User must be confirmed.
*/

const isBrowser = typeof navigator !== 'undefined';
const userAgent = isBrowser ? navigator.userAgent : 'nodejs';
const isNavigatorAvailable = typeof navigator !== 'undefined';
var specificUserAgent = isNavigatorAvailable ? navigator.userAgent : '';
if (isNavigatorAvailable && navigator.product === 'ReactNative')
specificUserAgent = 'react-native';
const userAgent = isNavigatorAvailable ? specificUserAgent : 'nodejs';
Samaritan1011001 marked this conversation as resolved.
Show resolved Hide resolved

/** @class */
export default class CognitoUser {
Expand Down
39 changes: 29 additions & 10 deletions packages/auth/__tests__/mockData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,32 +108,51 @@ export const mockDeviceArray = [
DeviceLastAuthenticatedDate: 1623954284,
DeviceLastModifiedDate: 1623954285.339,
},
{
DeviceAttributes: [
{
Name: 'device_status',
Value: 'valid',
},
{
Name: 'device_name',
Value: 'react-native',
},
{
Name: 'last_ip_used',
Value: '45.17.45.126',
},
],
DeviceCreateDate: 1623954284.75,
DeviceKey: 'us-west-2_80ede80b-f333-49cd-af42-0ad22d8de9d4',
DeviceLastAuthenticatedDate: 1623954285,
DeviceLastModifiedDate: 1623954285.34,
},
];

export const transformedMockData = [
{
id: 'us-east-2_596db07d-793a-4070-8140-27f321ccf01c',
name:
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.106 Safari/537.36',
name: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.106 Safari/537.36',
},
{
id: 'us-east-2_12ac778f-52a4-4fca-a628-237776159c91',
name:
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.106 Safari/537.36',
name: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.106 Safari/537.36',
},
{
id: 'us-east-2_4a93aeb3-01af-42d8-891d-ee8aa1549398',
name:
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.101 Safari/537.36',
name: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.101 Safari/537.36',
},
{
id: 'us-east-2_e0019223-e6b8-453f-a4e7-4e0d69dd4316',
name:
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.106 Safari/537.36',
name: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.106 Safari/537.36',
},
{
id: 'us-east-2_1763f940-7136-4133-8cf5-eb073cad06c9',
name:
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.106 Safari/537.36',
name: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.106 Safari/537.36',
},
{
id: 'us-west-2_80ede80b-f333-49cd-af42-0ad22d8de9d4',
name: 'react-native',
},
];