-
Notifications
You must be signed in to change notification settings - Fork 477
test(expo): drive the expo-native fixture from verify launch inputs #10052
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
Draft
mikepitre
wants to merge
2
commits into
main
Choose a base branch
from
mike/expo-verify-host
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+815
−3
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,2 @@ | ||
| --- | ||
| --- |
This file contains hidden or 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 hidden or 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,6 @@ | ||
| const { version: expoVersion } = require('expo/package.json'); | ||
|
|
||
| module.exports = ({ config }) => | ||
| expoVersion.startsWith('57.') | ||
| ? { ...config, plugins: [...config.plugins, ['expo-build-properties', { ios: { enableSceneSupport: true } }]] } | ||
| : config; | ||
This file contains hidden or 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,37 @@ | ||
| const fs = require('node:fs'); | ||
| const path = require('node:path'); | ||
| const { getDefaultConfig } = require('expo/metro-config'); | ||
| const { dependencies, devDependencies } = require('./package.json'); | ||
|
|
||
| const config = getDefaultConfig(__dirname); | ||
| const monorepoRoot = path.resolve(__dirname, '../../..'); | ||
| const fixtureEntry = path.join(__dirname, 'index.js'); | ||
| const fixturePackages = new Set(Object.keys({ ...dependencies, ...devDependencies })); | ||
|
|
||
| function linksToWorkspace() { | ||
| try { | ||
| return ( | ||
| fs.realpathSync(path.join(__dirname, 'node_modules/@clerk/expo')) === path.join(monorepoRoot, 'packages/expo') | ||
| ); | ||
| } catch { | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| function packageName(moduleName) { | ||
| const [scope, name] = moduleName.split('/'); | ||
| return scope.startsWith('@') ? `${scope}/${name}` : scope; | ||
| } | ||
|
|
||
| if (linksToWorkspace()) { | ||
| config.watchFolders = [monorepoRoot]; | ||
| config.resolver.resolveRequest = (context, moduleName, platform) => { | ||
| const fromWorkspace = !context.originModulePath.startsWith(__dirname + path.sep); | ||
| if (fromWorkspace && fixturePackages.has(packageName(moduleName))) { | ||
| return context.resolveRequest({ ...context, originModulePath: fixtureEntry }, moduleName, platform); | ||
| } | ||
| return context.resolveRequest(context, moduleName, platform); | ||
| }; | ||
| } | ||
|
|
||
| module.exports = config; |
15 changes: 15 additions & 0 deletions
15
integration/templates/expo-native/modules/verify-launch-config/android/build.gradle
This file contains hidden or 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,15 @@ | ||
| plugins { | ||
| id 'com.android.library' | ||
| id 'expo-module-gradle-plugin' | ||
| } | ||
|
|
||
| group = 'expo.modules.verifylaunchconfig' | ||
| version = '1.0.0' | ||
|
|
||
| android { | ||
| namespace "expo.modules.verifylaunchconfig" | ||
| defaultConfig { | ||
| versionCode 1 | ||
| versionName "1.0.0" | ||
| } | ||
| } |
2 changes: 2 additions & 0 deletions
2
...n/templates/expo-native/modules/verify-launch-config/android/src/main/AndroidManifest.xml
This file contains hidden or 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,2 @@ | ||
| <manifest> | ||
| </manifest> |
34 changes: 34 additions & 0 deletions
34
...-config/android/src/main/java/expo/modules/verifylaunchconfig/VerifyLaunchConfigModule.kt
This file contains hidden or 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,34 @@ | ||
| package expo.modules.verifylaunchconfig | ||
|
|
||
| import android.content.Context | ||
| import expo.modules.kotlin.modules.Module | ||
| import expo.modules.kotlin.modules.ModuleDefinition | ||
|
|
||
| private const val PREFERENCES = "verify_launch_config" | ||
| private const val STORAGE_SCOPE_KEY = "storageScope" | ||
| private val CLERK_STORAGE = listOf("clerk_preferences", "SecureStore") | ||
|
|
||
| class VerifyLaunchConfigModule : Module() { | ||
| override fun definition() = ModuleDefinition { | ||
| Name("VerifyLaunchConfig") | ||
|
|
||
| Function("readLaunchInputs") { | ||
| val extras = appContext.currentActivity?.intent?.extras ?: return@Function emptyMap<String, String>() | ||
| extras.keySet() | ||
| .filter { it.startsWith("verify") } | ||
| .mapNotNull { key -> extras.getString(key)?.let { key to it } } | ||
| .toMap() | ||
| } | ||
|
|
||
| Function("applyStorageScope") { scope: String -> | ||
| val context = appContext.reactContext ?: return@Function | ||
| val preferences = context.getSharedPreferences(PREFERENCES, Context.MODE_PRIVATE) | ||
| if (preferences.getString(STORAGE_SCOPE_KEY, null) == scope) { | ||
| return@Function | ||
| } | ||
|
|
||
| CLERK_STORAGE.forEach { context.deleteSharedPreferences(it) } | ||
| preferences.edit().putString(STORAGE_SCOPE_KEY, scope).commit() | ||
| } | ||
| } | ||
| } |
9 changes: 9 additions & 0 deletions
9
integration/templates/expo-native/modules/verify-launch-config/expo-module.config.json
This file contains hidden or 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,9 @@ | ||
| { | ||
| "platforms": ["apple", "android"], | ||
| "apple": { | ||
| "modules": ["VerifyLaunchConfigModule"] | ||
| }, | ||
| "android": { | ||
| "modules": ["expo.modules.verifylaunchconfig.VerifyLaunchConfigModule"] | ||
| } | ||
| } |
8 changes: 8 additions & 0 deletions
8
integration/templates/expo-native/modules/verify-launch-config/index.ts
This file contains hidden or 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,8 @@ | ||
| import { requireOptionalNativeModule } from 'expo'; | ||
|
|
||
| type VerifyLaunchConfigModule = { | ||
| readLaunchInputs(): Record<string, string>; | ||
| applyStorageScope(scope: string): void; | ||
| }; | ||
|
|
||
| export const VerifyLaunchConfig = requireOptionalNativeModule<VerifyLaunchConfigModule>('VerifyLaunchConfig'); |
18 changes: 18 additions & 0 deletions
18
...gration/templates/expo-native/modules/verify-launch-config/ios/VerifyLaunchConfig.podspec
This file contains hidden or 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,18 @@ | ||
| Pod::Spec.new do |s| | ||
| s.name = 'VerifyLaunchConfig' | ||
| s.version = '1.0.0' | ||
| s.summary = 'Reads verify launch inputs for the Expo native fixture' | ||
| s.author = '' | ||
| s.homepage = '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/clerk/javascript' | ||
| s.platforms = { :ios => '15.1' } | ||
| s.source = { git: '' } | ||
| s.static_framework = true | ||
|
|
||
| s.dependency 'ExpoModulesCore' | ||
|
|
||
| s.pod_target_xcconfig = { | ||
| 'DEFINES_MODULE' => 'YES', | ||
| } | ||
|
|
||
| s.source_files = "**/*.swift" | ||
| end |
48 changes: 48 additions & 0 deletions
48
...ion/templates/expo-native/modules/verify-launch-config/ios/VerifyLaunchConfigModule.swift
This file contains hidden or 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,48 @@ | ||
| import ExpoModulesCore | ||
| import Security | ||
|
|
||
| public class VerifyLaunchConfigModule: Module { | ||
| private static let storageScopeKey = "VerifyLaunchConfig.storageScope" | ||
| private static let clerkDefaultsKeys = [ | ||
| "authStartIdentifier", | ||
| "authStartPhoneNumber", | ||
| "authStartPhoneNumberFieldIsActive", | ||
| "clerk_last_used_identifier_type", | ||
| ] | ||
|
|
||
| public func definition() -> ModuleDefinition { | ||
| Name("VerifyLaunchConfig") | ||
|
|
||
| OnCreate { | ||
| if Self.launchInputs()["verifyLaunchId"] != nil { | ||
| Self.keepPasswordAutoFillOffNativeClerkViews() | ||
| } | ||
| } | ||
|
|
||
| Function("readLaunchInputs") { () -> [String: String] in | ||
| Self.launchInputs() | ||
| } | ||
|
|
||
| Function("applyStorageScope") { (scope: String) in | ||
| let defaults = UserDefaults.standard | ||
| guard defaults.string(forKey: Self.storageScopeKey) != scope else { | ||
| return | ||
| } | ||
|
|
||
| SecItemDelete([kSecClass: kSecClassGenericPassword] as CFDictionary) | ||
| Self.clerkDefaultsKeys.forEach(defaults.removeObject(forKey:)) | ||
| defaults.set(scope, forKey: Self.storageScopeKey) | ||
| } | ||
| } | ||
|
|
||
| private static func launchInputs() -> [String: String] { | ||
| UserDefaults.standard | ||
| .volatileDomain(forName: UserDefaults.argumentDomain) | ||
| .filter { $0.key.hasPrefix("verify") } | ||
| .compactMapValues { $0 as? String } | ||
| } | ||
|
|
||
| private static func keepPasswordAutoFillOffNativeClerkViews() { | ||
| setenv("CLERK_E2E_MODE", "1", 1) | ||
| } | ||
| } |
This file contains hidden or 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
74 changes: 74 additions & 0 deletions
74
integration/templates/expo-native/screens/CustomSignIn.tsx
This file contains hidden or 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,74 @@ | ||
| import { useSignIn } from '@clerk/expo'; | ||
| import { useState } from 'react'; | ||
| import { Button, Text, TextInput, View } from 'react-native'; | ||
|
|
||
| import { styles } from './styles'; | ||
|
|
||
| export function CustomSignIn() { | ||
| const { signIn, fetchStatus } = useSignIn(); | ||
| const [emailAddress, setEmailAddress] = useState(''); | ||
| const [code, setCode] = useState(''); | ||
| const [codeSent, setCodeSent] = useState(false); | ||
| const [error, setError] = useState<string | null>(null); | ||
| const busy = fetchStatus === 'fetching'; | ||
|
|
||
| const sendCode = async () => { | ||
| const { error } = await signIn.emailCode.sendCode({ emailAddress }); | ||
| setError(error?.message ?? null); | ||
| setCodeSent(!error); | ||
| }; | ||
|
|
||
| const verifyCode = async () => { | ||
| const { error } = await signIn.emailCode.verifyCode({ code }); | ||
| if (error || signIn.status !== 'complete') { | ||
| setError(error?.message ?? `Sign-in is ${signIn.status}`); | ||
| return; | ||
| } | ||
| const finalized = await signIn.finalize(); | ||
| setError(finalized.error?.message ?? null); | ||
| }; | ||
|
|
||
| return ( | ||
| <View style={styles.form}> | ||
| <Text style={styles.title}>Custom sign-in</Text> | ||
| {codeSent ? ( | ||
| <> | ||
| <TextInput | ||
| testID='verify.customSignIn.code' | ||
| style={styles.input} | ||
| value={code} | ||
| onChangeText={setCode} | ||
| placeholder='Email code' | ||
| keyboardType='number-pad' | ||
| autoComplete='one-time-code' | ||
| /> | ||
| <Button | ||
| testID='verify.customSignIn.verifyCode' | ||
| title='Verify code' | ||
| disabled={busy} | ||
| onPress={() => void verifyCode()} | ||
| /> | ||
| </> | ||
| ) : ( | ||
| <> | ||
| <TextInput | ||
| testID='verify.customSignIn.emailAddress' | ||
| style={styles.input} | ||
| value={emailAddress} | ||
| onChangeText={setEmailAddress} | ||
| placeholder='Email address' | ||
| autoCapitalize='none' | ||
| keyboardType='email-address' | ||
| /> | ||
| <Button | ||
| testID='verify.customSignIn.sendCode' | ||
| title='Send code' | ||
| disabled={busy} | ||
| onPress={() => void sendCode()} | ||
| /> | ||
| </> | ||
| )} | ||
| {error && <Text testID='verify.customSignIn.error'>{error}</Text>} | ||
| </View> | ||
| ); | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.