-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add module loader for web browser native module (#12519)
Co-authored-by: Ashwin Kumar <[email protected]>
- Loading branch information
1 parent
7b514bb
commit 7dde343
Showing
11 changed files
with
72 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
packages/react-native/src/moduleLoaders/loadAmplifyWebBrowser.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import type { WebBrowserModule } from '@aws-amplify/rtn-web-browser'; | ||
|
||
export const loadAmplifyWebBrowser = () => { | ||
try { | ||
// metro bundler requires static string for loading module. | ||
// See: https://facebook.github.io/metro/docs/configuration/#dynamicdepsinpackages | ||
const module = require('@aws-amplify/rtn-web-browser') | ||
?.module as WebBrowserModule; | ||
if (module) { | ||
return module; | ||
} | ||
|
||
throw new Error( | ||
'Ensure `@aws-amplify/rtn-web-browser` is installed and linked.' | ||
); | ||
} catch (e) { | ||
// The error parsing logic cannot be extracted with metro as the `require` | ||
// would be confused when there is a `import` in the same file importing | ||
// another module and that causes an error | ||
const message = (e as Error).message.replace( | ||
/undefined/g, | ||
'@aws-amplify/rtn-web-browser' | ||
); | ||
throw new Error(message); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
export { openAuthSessionAsync } from './openAuthSessionAsync'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
import { Platform } from 'react-native'; | ||
|
||
// General | ||
export const PACKAGE_NAME = '@aws-amplify/rtn-web-browser'; | ||
export const LINKING_ERROR = | ||
`The ${PACKAGE_NAME} package doesn't seem to be linked. Make sure: \n\n` + | ||
Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) + | ||
'- You rebuilt the app after installing the package\n' + | ||
'- You are not using Expo Go\n'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,9 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { openAuthSessionAsync } from './apis/openAuthSessionAsync'; | ||
import { nativeModule } from './nativeModule'; | ||
import { openAuthSessionAsync } from './apis'; | ||
|
||
const mergedModule = { | ||
...nativeModule, | ||
openAuthSessionAsync, | ||
}; | ||
const module = { openAuthSessionAsync }; | ||
|
||
export { mergedModule as AmplifyRTNWebBrowser }; | ||
export type WebBrowserModule = typeof module; | ||
export { module }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
export * from './native'; |
6 changes: 4 additions & 2 deletions
6
packages/rtn-web-browser/src/types.ts → packages/rtn-web-browser/src/types/native.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
export type WebBrowserNativeModule = { | ||
import { NativeModule } from 'react-native'; | ||
|
||
export interface WebBrowserNativeModule extends NativeModule { | ||
openAuthSessionAsync: ( | ||
url: string, | ||
redirectUrl?: string, | ||
prefersEphemeralSession?: boolean | ||
) => Promise<string | null>; | ||
}; | ||
} |