UNPKG

10.9 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, '__esModule', { value: true });
4
5var ReactNative = require('react-native');
6var app = require('@firebase/app');
7var phone = require('./phone-cf00e1ee.js');
8var tslib = require('tslib');
9require('@firebase/util');
10require('@firebase/component');
11require('@firebase/logger');
12
13function _interopNamespace(e) {
14 if (e && e.__esModule) return e;
15 var n = Object.create(null);
16 if (e) {
17 Object.keys(e).forEach(function (k) {
18 if (k !== 'default') {
19 var d = Object.getOwnPropertyDescriptor(e, k);
20 Object.defineProperty(n, k, d.get ? d : {
21 enumerable: true,
22 get: function () { return e[k]; }
23 });
24 }
25 });
26 }
27 n["default"] = e;
28 return Object.freeze(n);
29}
30
31var ReactNative__namespace = /*#__PURE__*/_interopNamespace(ReactNative);
32
33/**
34 * @license
35 * Copyright 2019 Google LLC
36 *
37 * Licensed under the Apache License, Version 2.0 (the "License");
38 * you may not use this file except in compliance with the License.
39 * You may obtain a copy of the License at
40 *
41 * http://www.apache.org/licenses/LICENSE-2.0
42 *
43 * Unless required by applicable law or agreed to in writing, software
44 * distributed under the License is distributed on an "AS IS" BASIS,
45 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
46 * See the License for the specific language governing permissions and
47 * limitations under the License.
48 */
49/**
50 * Returns a persistence object that wraps `AsyncStorage` imported from
51 * `react-native` or `@react-native-community/async-storage`, and can
52 * be used in the persistence dependency field in {@link initializeAuth}.
53 *
54 * @public
55 */
56function getReactNativePersistence(storage) {
57 var _a;
58 // In the _getInstance() implementation (see src/core/persistence/index.ts),
59 // we expect each "externs.Persistence" object passed to us by the user to
60 // be able to be instantiated (as a class) using "new". That function also
61 // expects the constructor to be empty. Since ReactNativeStorage requires the
62 // underlying storage layer, we need to be able to create subclasses
63 // (closures, esentially) that have the storage layer but empty constructor.
64 return _a = /** @class */ (function () {
65 function class_1() {
66 this.type = "LOCAL" /* LOCAL */;
67 }
68 class_1.prototype._isAvailable = function () {
69 return tslib.__awaiter(this, void 0, void 0, function () {
70 return tslib.__generator(this, function (_b) {
71 switch (_b.label) {
72 case 0:
73 _b.trys.push([0, 3, , 4]);
74 if (!storage) {
75 return [2 /*return*/, false];
76 }
77 return [4 /*yield*/, storage.setItem(phone.STORAGE_AVAILABLE_KEY, '1')];
78 case 1:
79 _b.sent();
80 return [4 /*yield*/, storage.removeItem(phone.STORAGE_AVAILABLE_KEY)];
81 case 2:
82 _b.sent();
83 return [2 /*return*/, true];
84 case 3:
85 _b.sent();
86 return [2 /*return*/, false];
87 case 4: return [2 /*return*/];
88 }
89 });
90 });
91 };
92 class_1.prototype._set = function (key, value) {
93 return storage.setItem(key, JSON.stringify(value));
94 };
95 class_1.prototype._get = function (key) {
96 return tslib.__awaiter(this, void 0, void 0, function () {
97 var json;
98 return tslib.__generator(this, function (_a) {
99 switch (_a.label) {
100 case 0: return [4 /*yield*/, storage.getItem(key)];
101 case 1:
102 json = _a.sent();
103 return [2 /*return*/, json ? JSON.parse(json) : null];
104 }
105 });
106 });
107 };
108 class_1.prototype._remove = function (key) {
109 return storage.removeItem(key);
110 };
111 class_1.prototype._addListener = function (_key, _listener) {
112 // Listeners are not supported for React Native storage.
113 return;
114 };
115 class_1.prototype._removeListener = function (_key, _listener) {
116 // Listeners are not supported for React Native storage.
117 return;
118 };
119 return class_1;
120 }()),
121 _a.type = 'LOCAL',
122 _a;
123}
124
125/**
126 * @license
127 * Copyright 2017 Google LLC
128 *
129 * Licensed under the Apache License, Version 2.0 (the "License");
130 * you may not use this file except in compliance with the License.
131 * You may obtain a copy of the License at
132 *
133 * http://www.apache.org/licenses/LICENSE-2.0
134 *
135 * Unless required by applicable law or agreed to in writing, software
136 * distributed under the License is distributed on an "AS IS" BASIS,
137 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
138 * See the License for the specific language governing permissions and
139 * limitations under the License.
140 */
141/**
142 * An implementation of {@link Persistence} of type 'LOCAL' for use in React
143 * Native environments.
144 *
145 * @public
146 */
147var reactNativeLocalPersistence = getReactNativePersistence({
148 getItem: function () {
149 var _a;
150 var args = [];
151 for (var _i = 0; _i < arguments.length; _i++) {
152 args[_i] = arguments[_i];
153 }
154 // Called inline to avoid deprecation warnings on startup.
155 return (_a = ReactNative__namespace.AsyncStorage).getItem.apply(_a, args);
156 },
157 setItem: function () {
158 var _a;
159 var args = [];
160 for (var _i = 0; _i < arguments.length; _i++) {
161 args[_i] = arguments[_i];
162 }
163 // Called inline to avoid deprecation warnings on startup.
164 return (_a = ReactNative__namespace.AsyncStorage).setItem.apply(_a, args);
165 },
166 removeItem: function () {
167 var _a;
168 var args = [];
169 for (var _i = 0; _i < arguments.length; _i++) {
170 args[_i] = arguments[_i];
171 }
172 // Called inline to avoid deprecation warnings on startup.
173 return (_a = ReactNative__namespace.AsyncStorage).removeItem.apply(_a, args);
174 },
175});
176function getAuth(app$1) {
177 if (app$1 === void 0) { app$1 = app.getApp(); }
178 var provider = app._getProvider(app$1, 'auth');
179 if (provider.isInitialized()) {
180 return provider.getImmediate();
181 }
182 return phone.initializeAuth(app$1, {
183 persistence: reactNativeLocalPersistence
184 });
185}
186phone.registerAuth("ReactNative" /* REACT_NATIVE */);
187
188exports.ActionCodeOperation = phone.ActionCodeOperation;
189exports.ActionCodeURL = phone.ActionCodeURL;
190exports.AuthCredential = phone.AuthCredential;
191exports.AuthErrorCodes = phone.AUTH_ERROR_CODES_MAP_DO_NOT_USE_INTERNALLY;
192exports.EmailAuthCredential = phone.EmailAuthCredential;
193exports.EmailAuthProvider = phone.EmailAuthProvider;
194exports.FacebookAuthProvider = phone.FacebookAuthProvider;
195exports.FactorId = phone.FactorId;
196exports.GithubAuthProvider = phone.GithubAuthProvider;
197exports.GoogleAuthProvider = phone.GoogleAuthProvider;
198exports.OAuthCredential = phone.OAuthCredential;
199exports.OAuthProvider = phone.OAuthProvider;
200exports.OperationType = phone.OperationType;
201exports.PhoneAuthCredential = phone.PhoneAuthCredential;
202exports.PhoneAuthProvider = phone.PhoneAuthProvider;
203exports.PhoneMultiFactorGenerator = phone.PhoneMultiFactorGenerator;
204exports.ProviderId = phone.ProviderId;
205exports.SAMLAuthProvider = phone.SAMLAuthProvider;
206exports.SignInMethod = phone.SignInMethod;
207exports.TwitterAuthProvider = phone.TwitterAuthProvider;
208exports.applyActionCode = phone.applyActionCode;
209exports.beforeAuthStateChanged = phone.beforeAuthStateChanged;
210exports.checkActionCode = phone.checkActionCode;
211exports.confirmPasswordReset = phone.confirmPasswordReset;
212exports.connectAuthEmulator = phone.connectAuthEmulator;
213exports.createUserWithEmailAndPassword = phone.createUserWithEmailAndPassword;
214exports.debugErrorMap = phone.debugErrorMap;
215exports.deleteUser = phone.deleteUser;
216exports.fetchSignInMethodsForEmail = phone.fetchSignInMethodsForEmail;
217exports.getAdditionalUserInfo = phone.getAdditionalUserInfo;
218exports.getIdToken = phone.getIdToken;
219exports.getIdTokenResult = phone.getIdTokenResult;
220exports.getMultiFactorResolver = phone.getMultiFactorResolver;
221exports.inMemoryPersistence = phone.inMemoryPersistence;
222exports.initializeAuth = phone.initializeAuth;
223exports.isSignInWithEmailLink = phone.isSignInWithEmailLink;
224exports.linkWithCredential = phone.linkWithCredential;
225exports.linkWithPhoneNumber = phone.linkWithPhoneNumber;
226exports.multiFactor = phone.multiFactor;
227exports.onAuthStateChanged = phone.onAuthStateChanged;
228exports.onIdTokenChanged = phone.onIdTokenChanged;
229exports.parseActionCodeURL = phone.parseActionCodeURL;
230exports.prodErrorMap = phone.prodErrorMap;
231exports.reauthenticateWithCredential = phone.reauthenticateWithCredential;
232exports.reauthenticateWithPhoneNumber = phone.reauthenticateWithPhoneNumber;
233exports.reload = phone.reload;
234exports.sendEmailVerification = phone.sendEmailVerification;
235exports.sendPasswordResetEmail = phone.sendPasswordResetEmail;
236exports.sendSignInLinkToEmail = phone.sendSignInLinkToEmail;
237exports.setPersistence = phone.setPersistence;
238exports.signInAnonymously = phone.signInAnonymously;
239exports.signInWithCredential = phone.signInWithCredential;
240exports.signInWithCustomToken = phone.signInWithCustomToken;
241exports.signInWithEmailAndPassword = phone.signInWithEmailAndPassword;
242exports.signInWithEmailLink = phone.signInWithEmailLink;
243exports.signInWithPhoneNumber = phone.signInWithPhoneNumber;
244exports.signOut = phone.signOut;
245exports.unlink = phone.unlink;
246exports.updateCurrentUser = phone.updateCurrentUser;
247exports.updateEmail = phone.updateEmail;
248exports.updatePassword = phone.updatePassword;
249exports.updatePhoneNumber = phone.updatePhoneNumber;
250exports.updateProfile = phone.updateProfile;
251exports.useDeviceLanguage = phone.useDeviceLanguage;
252exports.verifyBeforeUpdateEmail = phone.verifyBeforeUpdateEmail;
253exports.verifyPasswordResetCode = phone.verifyPasswordResetCode;
254exports.getAuth = getAuth;
255exports.getReactNativePersistence = getReactNativePersistence;
256exports.reactNativeLocalPersistence = reactNativeLocalPersistence;
257//# sourceMappingURL=index.js.map