@react-native-firebase/auth 16.3.1 → 16.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,16 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ### [16.4.1](https://github.com/invertase/react-native-firebase/compare/v16.4.0...v16.4.1) (2022-11-02)
7
+
8
+ **Note:** Version bump only for package @react-native-firebase/auth
9
+
10
+ ## [16.4.0](https://github.com/invertase/react-native-firebase/compare/v16.3.1...v16.4.0) (2022-10-30)
11
+
12
+ ### Features
13
+
14
+ - **auth:** Add Expo support for phone auth ([#6645](https://github.com/invertase/react-native-firebase/issues/6645)) ([97a4ea5](https://github.com/invertase/react-native-firebase/commit/97a4ea573dd0795b157e73299e705dbd7bb7e3d4))
15
+
6
16
  ### [16.3.1](https://github.com/invertase/react-native-firebase/compare/v16.3.0...v16.3.1) (2022-10-28)
7
17
 
8
18
  **Note:** Version bump only for package @react-native-firebase/auth
package/app.plugin.js ADDED
@@ -0,0 +1 @@
1
+ module.exports = require('./plugin/build');
package/lib/version.js CHANGED
@@ -1,2 +1,2 @@
1
1
  // Generated by genversion.
2
- module.exports = '16.3.1';
2
+ module.exports = '16.4.1';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-native-firebase/auth",
3
- "version": "16.3.1",
3
+ "version": "16.4.1",
4
4
  "author": "Invertase <oss@invertase.io> (http://invertase.io)",
5
5
  "description": "React Native Firebase - The authentication module provides an easy-to-use API to integrate an authentication workflow into new and existing applications. React Native Firebase provides access to all Firebase authentication methods and identity providers.",
6
6
  "main": "lib/index.js",
@@ -8,7 +8,9 @@
8
8
  "scripts": {
9
9
  "build": "genversion --semi lib/version.js",
10
10
  "build:clean": "rimraf android/build && rimraf ios/build",
11
- "prepare": "yarn run build"
11
+ "build:plugin": "rimraf plugin/build && tsc --build plugin",
12
+ "lint:plugin": "eslint plugin/src/*",
13
+ "prepare": "yarn run build && yarn run build:plugin"
12
14
  },
13
15
  "repository": {
14
16
  "type": "git",
@@ -21,11 +23,18 @@
21
23
  "firebase",
22
24
  "auth"
23
25
  ],
26
+ "dependencies": {
27
+ "@expo/config-plugins": "^5.0.1",
28
+ "plist": "^3.0.5"
29
+ },
24
30
  "peerDependencies": {
25
- "@react-native-firebase/app": "16.3.1"
31
+ "@react-native-firebase/app": "16.4.1"
26
32
  },
27
33
  "publishConfig": {
28
34
  "access": "public"
29
35
  },
30
- "gitHead": "1f2385bfb90ee5cad2aab23332d1d13fdf0d81c2"
36
+ "devDependencies": {
37
+ "@types/plist": "^3.0.2"
38
+ },
39
+ "gitHead": "542cec866fb2e83b7fc4baf3be287bc2c3408229"
31
40
  }
@@ -0,0 +1,13 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`Config Plugin iOS Tests adds url types to the Info.plist 1`] = `
4
+ {
5
+ "CFBundleURLTypes": [
6
+ {
7
+ "CFBundleURLSchemes": [
8
+ "com.googleusercontent.apps.SomeRandomClientIdString",
9
+ ],
10
+ },
11
+ ],
12
+ }
13
+ `;
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <plist version="1.0">
4
+ <dict>
5
+ </dict>
6
+ </plist>
@@ -0,0 +1,38 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <plist version="1.0">
4
+ <dict>
5
+ <key>CLIENT_ID</key>
6
+ <string>SomeRandomClientIdString.apps.googleusercontent.com</string>
7
+ <key>REVERSED_CLIENT_ID</key>
8
+ <string>com.googleusercontent.apps.SomeRandomClientIdString</string>
9
+ <key>ANDROID_CLIENT_ID</key>
10
+ <string>SomeRandomAndroidClientIdString.apps.googleusercontent.com</string>
11
+ <key>API_KEY</key>
12
+ <string>SomeRandomApiKeyString</string>
13
+ <key>GCM_SENDER_ID</key>
14
+ <string>SomeRandomGcmSenderIdNumber</string>
15
+ <key>PLIST_VERSION</key>
16
+ <string>1</string>
17
+ <key>BUNDLE_ID</key>
18
+ <string>com.example.app</string>
19
+ <key>PROJECT_ID</key>
20
+ <string>example</string>
21
+ <key>STORAGE_BUCKET</key>
22
+ <string>example.appspot.com</string>
23
+ <key>IS_ADS_ENABLED</key>
24
+ <false></false>
25
+ <key>IS_ANALYTICS_ENABLED</key>
26
+ <false></false>
27
+ <key>IS_APPINVITE_ENABLED</key>
28
+ <true></true>
29
+ <key>IS_GCM_ENABLED</key>
30
+ <true></true>
31
+ <key>IS_SIGNIN_ENABLED</key>
32
+ <true></true>
33
+ <key>GOOGLE_APP_ID</key>
34
+ <string>1234:1234:ios:1234</string>
35
+ <key>DATABASE_URL</key>
36
+ <string>https://example.firebaseio.com</string>
37
+ </dict>
38
+ </plist>
@@ -0,0 +1,75 @@
1
+ import path from 'path';
2
+ import { beforeEach, describe, expect, it, jest } from '@jest/globals';
3
+ import { setUrlTypesForCaptcha } from '../src/ios/urlTypes';
4
+
5
+ describe('Config Plugin iOS Tests', () => {
6
+ beforeEach(function () {
7
+ jest.resetAllMocks();
8
+ });
9
+
10
+ it('throws if path to GoogleServer-Info.plist is not provided', async () => {
11
+ expect(() => {
12
+ setUrlTypesForCaptcha({
13
+ config: {
14
+ name: 'TestName',
15
+ slug: 'TestSlug',
16
+ modRequest: { projectRoot: path.join(__dirname, 'fixtures') } as any,
17
+ modResults: {},
18
+ modRawConfig: { name: 'TestName', slug: 'TestSlug' },
19
+ ios: {},
20
+ },
21
+ });
22
+ }).toThrow(
23
+ `[@react-native-firebase/auth] Your app.json file is missing ios.googleServicesFile. Please add this field.`,
24
+ );
25
+ });
26
+
27
+ it('throws if GoogleServer-Info.plist cannot be read', async () => {
28
+ const googleServiceFilePath = path.join(__dirname, 'fixtures', 'ThisFileDoesNotExist.plist');
29
+ expect(() => {
30
+ setUrlTypesForCaptcha({
31
+ config: {
32
+ name: 'TestName',
33
+ slug: 'TestSlug',
34
+ modRequest: { projectRoot: path.join(__dirname, 'fixtures') } as any,
35
+ modResults: {},
36
+ modRawConfig: { name: 'TestName', slug: 'TestSlug' },
37
+ ios: { googleServicesFile: 'ThisFileDoesNotExist.plist' },
38
+ },
39
+ });
40
+ }).toThrow(
41
+ `[@react-native-firebase/auth] GoogleService-Info.plist doesn't exist in ${googleServiceFilePath}. Place it there or configure the path in app.json`,
42
+ );
43
+ });
44
+
45
+ it('throws if GoogleServer-Info.plist has no reversed client id', async () => {
46
+ expect(() => {
47
+ setUrlTypesForCaptcha({
48
+ config: {
49
+ name: 'TestName',
50
+ slug: 'TestSlug',
51
+ modRequest: { projectRoot: path.join(__dirname, 'fixtures') } as any,
52
+ modResults: {},
53
+ modRawConfig: { name: 'TestName', slug: 'TestSlug' },
54
+ ios: { googleServicesFile: 'TestGoogleService-Info.incomplete.plist' },
55
+ },
56
+ });
57
+ }).toThrow(
58
+ '[@react-native-firebase/auth] Failed to parse your GoogleService-Info.plist. Are you sure it is a valid Info.Plist file with a REVERSE_CLIENT_ID field?',
59
+ );
60
+ });
61
+
62
+ it('adds url types to the Info.plist', async () => {
63
+ const result = setUrlTypesForCaptcha({
64
+ config: {
65
+ name: 'TestName',
66
+ slug: 'TestSlug',
67
+ modRequest: { projectRoot: path.join(__dirname, 'fixtures') } as any,
68
+ modResults: {},
69
+ modRawConfig: { name: 'TestName', slug: 'TestSlug' },
70
+ ios: { googleServicesFile: 'TestGoogleService-Info.plist' },
71
+ },
72
+ });
73
+ expect(result.modResults).toMatchSnapshot();
74
+ });
75
+ });
@@ -0,0 +1,3 @@
1
+ import { ConfigPlugin } from '@expo/config-plugins';
2
+ declare const _default: ConfigPlugin<void>;
3
+ export default _default;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const config_plugins_1 = require("@expo/config-plugins");
4
+ const ios_1 = require("./ios");
5
+ /**
6
+ * A config plugin for configuring `@react-native-firebase/auth`
7
+ */
8
+ const withRnFirebaseAuth = config => {
9
+ return (0, config_plugins_1.withPlugins)(config, [
10
+ // iOS
11
+ ios_1.withIosCaptchaUrlTypes,
12
+ ]);
13
+ };
14
+ const pak = require('@react-native-firebase/auth/package.json');
15
+ exports.default = (0, config_plugins_1.createRunOncePlugin)(withRnFirebaseAuth, pak.name, pak.version);
@@ -0,0 +1,2 @@
1
+ import { withIosCaptchaUrlTypes } from './urlTypes';
2
+ export { withIosCaptchaUrlTypes };
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.withIosCaptchaUrlTypes = void 0;
4
+ const urlTypes_1 = require("./urlTypes");
5
+ Object.defineProperty(exports, "withIosCaptchaUrlTypes", { enumerable: true, get: function () { return urlTypes_1.withIosCaptchaUrlTypes; } });
@@ -0,0 +1,5 @@
1
+ import { ConfigPlugin, IOSConfig, ExportedConfigWithProps } from '@expo/config-plugins';
2
+ export declare const withIosCaptchaUrlTypes: ConfigPlugin;
3
+ export declare function setUrlTypesForCaptcha({ config, }: {
4
+ config: ExportedConfigWithProps<IOSConfig.InfoPlist>;
5
+ }): ExportedConfigWithProps<IOSConfig.InfoPlist>;
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.setUrlTypesForCaptcha = exports.withIosCaptchaUrlTypes = void 0;
7
+ const config_plugins_1 = require("@expo/config-plugins");
8
+ const fs_1 = __importDefault(require("fs"));
9
+ const path_1 = __importDefault(require("path"));
10
+ const plist_1 = __importDefault(require("plist"));
11
+ // does this for you: https://firebase.google.com/docs/auth/ios/phone-auth#enable-phone-number-sign-in-for-your-firebase-project
12
+ const withIosCaptchaUrlTypes = config => {
13
+ return (0, config_plugins_1.withInfoPlist)(config, config => {
14
+ return setUrlTypesForCaptcha({ config });
15
+ });
16
+ };
17
+ exports.withIosCaptchaUrlTypes = withIosCaptchaUrlTypes;
18
+ function getReversedClientId(googleServiceFilePath) {
19
+ try {
20
+ const googleServicePlist = fs_1.default.readFileSync(googleServiceFilePath, 'utf8');
21
+ const googleServiceJson = plist_1.default.parse(googleServicePlist);
22
+ const REVERSED_CLIENT_ID = googleServiceJson.REVERSED_CLIENT_ID;
23
+ if (!REVERSED_CLIENT_ID) {
24
+ throw new TypeError('REVERSED_CLIENT_ID missing');
25
+ }
26
+ return REVERSED_CLIENT_ID;
27
+ }
28
+ catch {
29
+ throw new Error('[@react-native-firebase/auth] Failed to parse your GoogleService-Info.plist. Are you sure it is a valid Info.Plist file with a REVERSE_CLIENT_ID field?');
30
+ }
31
+ }
32
+ // add phone auth support by configuring recaptcha
33
+ // https://github.com/invertase/react-native-firebase/pull/6167
34
+ function addUriScheme(config, reversedClientId) {
35
+ var _a;
36
+ if (!config.modResults) {
37
+ config.modResults = {};
38
+ }
39
+ if (!config.modResults.CFBundleURLTypes) {
40
+ config.modResults.CFBundleURLTypes = [];
41
+ }
42
+ const hasReverseClientId = (_a = config.modResults.CFBundleURLTypes) === null || _a === void 0 ? void 0 : _a.some(urlType => urlType.CFBundleURLSchemes.includes(reversedClientId));
43
+ if (!hasReverseClientId) {
44
+ config.modResults.CFBundleURLTypes.push({
45
+ CFBundleURLSchemes: [reversedClientId],
46
+ });
47
+ }
48
+ return config;
49
+ }
50
+ function setUrlTypesForCaptcha({ config, }) {
51
+ var _a;
52
+ const googleServicesFileRelativePath = (_a = config.ios) === null || _a === void 0 ? void 0 : _a.googleServicesFile;
53
+ if (!googleServicesFileRelativePath) {
54
+ throw new Error(`[@react-native-firebase/auth] Your app.json file is missing ios.googleServicesFile. Please add this field.`);
55
+ }
56
+ const googleServiceFilePath = path_1.default.resolve(config.modRequest.projectRoot, googleServicesFileRelativePath);
57
+ if (!fs_1.default.existsSync(googleServiceFilePath)) {
58
+ throw new Error(`[@react-native-firebase/auth] GoogleService-Info.plist doesn't exist in ${googleServiceFilePath}. Place it there or configure the path in app.json`);
59
+ }
60
+ const reversedClientId = getReversedClientId(googleServiceFilePath);
61
+ addUriScheme(config, reversedClientId);
62
+ return config;
63
+ }
64
+ exports.setUrlTypesForCaptcha = setUrlTypesForCaptcha;
@@ -0,0 +1,16 @@
1
+ import { ConfigPlugin, withPlugins, createRunOncePlugin } from '@expo/config-plugins';
2
+
3
+ import { withIosCaptchaUrlTypes } from './ios';
4
+
5
+ /**
6
+ * A config plugin for configuring `@react-native-firebase/auth`
7
+ */
8
+ const withRnFirebaseAuth: ConfigPlugin = config => {
9
+ return withPlugins(config, [
10
+ // iOS
11
+ withIosCaptchaUrlTypes,
12
+ ]);
13
+ };
14
+
15
+ const pak = require('@react-native-firebase/auth/package.json');
16
+ export default createRunOncePlugin(withRnFirebaseAuth, pak.name, pak.version);
@@ -0,0 +1,3 @@
1
+ import { withIosCaptchaUrlTypes } from './urlTypes';
2
+
3
+ export { withIosCaptchaUrlTypes };
@@ -0,0 +1,90 @@
1
+ import {
2
+ ConfigPlugin,
3
+ IOSConfig,
4
+ withInfoPlist,
5
+ ExportedConfigWithProps,
6
+ } from '@expo/config-plugins';
7
+ import fs from 'fs';
8
+ import path from 'path';
9
+ import plist from 'plist';
10
+
11
+ // does this for you: https://firebase.google.com/docs/auth/ios/phone-auth#enable-phone-number-sign-in-for-your-firebase-project
12
+ export const withIosCaptchaUrlTypes: ConfigPlugin = config => {
13
+ return withInfoPlist(config, config => {
14
+ return setUrlTypesForCaptcha({ config });
15
+ });
16
+ };
17
+
18
+ function getReversedClientId(googleServiceFilePath: string): string {
19
+ try {
20
+ const googleServicePlist = fs.readFileSync(googleServiceFilePath, 'utf8');
21
+
22
+ const googleServiceJson = plist.parse(googleServicePlist) as { REVERSED_CLIENT_ID: string };
23
+ const REVERSED_CLIENT_ID = googleServiceJson.REVERSED_CLIENT_ID;
24
+
25
+ if (!REVERSED_CLIENT_ID) {
26
+ throw new TypeError('REVERSED_CLIENT_ID missing');
27
+ }
28
+
29
+ return REVERSED_CLIENT_ID;
30
+ } catch {
31
+ throw new Error(
32
+ '[@react-native-firebase/auth] Failed to parse your GoogleService-Info.plist. Are you sure it is a valid Info.Plist file with a REVERSE_CLIENT_ID field?',
33
+ );
34
+ }
35
+ }
36
+
37
+ // add phone auth support by configuring recaptcha
38
+ // https://github.com/invertase/react-native-firebase/pull/6167
39
+ function addUriScheme(
40
+ config: ExportedConfigWithProps<IOSConfig.InfoPlist>,
41
+ reversedClientId: string,
42
+ ): ExportedConfigWithProps<IOSConfig.InfoPlist> {
43
+ if (!config.modResults) {
44
+ config.modResults = {};
45
+ }
46
+
47
+ if (!config.modResults.CFBundleURLTypes) {
48
+ config.modResults.CFBundleURLTypes = [];
49
+ }
50
+
51
+ const hasReverseClientId = config.modResults.CFBundleURLTypes?.some(urlType =>
52
+ urlType.CFBundleURLSchemes.includes(reversedClientId),
53
+ );
54
+
55
+ if (!hasReverseClientId) {
56
+ config.modResults.CFBundleURLTypes.push({
57
+ CFBundleURLSchemes: [reversedClientId],
58
+ });
59
+ }
60
+
61
+ return config;
62
+ }
63
+
64
+ export function setUrlTypesForCaptcha({
65
+ config,
66
+ }: {
67
+ config: ExportedConfigWithProps<IOSConfig.InfoPlist>;
68
+ }) {
69
+ const googleServicesFileRelativePath = config.ios?.googleServicesFile;
70
+ if (!googleServicesFileRelativePath) {
71
+ throw new Error(
72
+ `[@react-native-firebase/auth] Your app.json file is missing ios.googleServicesFile. Please add this field.`,
73
+ );
74
+ }
75
+ const googleServiceFilePath = path.resolve(
76
+ config.modRequest.projectRoot,
77
+ googleServicesFileRelativePath,
78
+ );
79
+
80
+ if (!fs.existsSync(googleServiceFilePath)) {
81
+ throw new Error(
82
+ `[@react-native-firebase/auth] GoogleService-Info.plist doesn't exist in ${googleServiceFilePath}. Place it there or configure the path in app.json`,
83
+ );
84
+ }
85
+
86
+ const reversedClientId = getReversedClientId(googleServiceFilePath);
87
+ addUriScheme(config, reversedClientId);
88
+
89
+ return config;
90
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "@tsconfig/node12/tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "build",
5
+ "rootDir": "src",
6
+ "declaration": true
7
+ },
8
+ "include": ["./src"]
9
+ }