@tern-secure/auth 1.0.0
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/dist/cjs/global.d.js +2 -0
- package/dist/cjs/global.d.js.map +1 -0
- package/dist/cjs/index.js +42 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/instance/TernAuth.js +471 -0
- package/dist/cjs/instance/TernAuth.js.map +1 -0
- package/dist/cjs/instance/TernAuthServer.js +95 -0
- package/dist/cjs/instance/TernAuthServer.js.map +1 -0
- package/dist/cjs/instance/coreApiClient.example.js +96 -0
- package/dist/cjs/instance/coreApiClient.example.js.map +1 -0
- package/dist/cjs/instance/coreApiClient.js +255 -0
- package/dist/cjs/instance/coreApiClient.js.map +1 -0
- package/dist/cjs/instance/events.js +38 -0
- package/dist/cjs/instance/events.js.map +1 -0
- package/dist/cjs/resources/AuthCookieManager.js +89 -0
- package/dist/cjs/resources/AuthCookieManager.js.map +1 -0
- package/dist/cjs/resources/Base.js +125 -0
- package/dist/cjs/resources/Base.js.map +1 -0
- package/dist/cjs/resources/Error.js +31 -0
- package/dist/cjs/resources/Error.js.map +1 -0
- package/dist/cjs/resources/SignIn.js +224 -0
- package/dist/cjs/resources/SignIn.js.map +1 -0
- package/dist/cjs/resources/SignUp.js +43 -0
- package/dist/cjs/resources/SignUp.js.map +1 -0
- package/dist/cjs/resources/index.js +23 -0
- package/dist/cjs/resources/index.js.map +1 -0
- package/dist/cjs/resources/internal.js +33 -0
- package/dist/cjs/resources/internal.js.map +1 -0
- package/dist/cjs/utils/construct.js +174 -0
- package/dist/cjs/utils/construct.js.map +1 -0
- package/dist/cjs/utils/index.js +25 -0
- package/dist/cjs/utils/index.js.map +1 -0
- package/dist/cjs/utils/querystring.js +70 -0
- package/dist/cjs/utils/querystring.js.map +1 -0
- package/dist/esm/global.d.js +1 -0
- package/dist/esm/global.d.js.map +1 -0
- package/dist/esm/index.js +13 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/instance/TernAuth.js +455 -0
- package/dist/esm/instance/TernAuth.js.map +1 -0
- package/dist/esm/instance/TernAuthServer.js +73 -0
- package/dist/esm/instance/TernAuthServer.js.map +1 -0
- package/dist/esm/instance/coreApiClient.example.js +70 -0
- package/dist/esm/instance/coreApiClient.example.js.map +1 -0
- package/dist/esm/instance/coreApiClient.js +226 -0
- package/dist/esm/instance/coreApiClient.js.map +1 -0
- package/dist/esm/instance/events.js +13 -0
- package/dist/esm/instance/events.js.map +1 -0
- package/dist/esm/resources/AuthCookieManager.js +67 -0
- package/dist/esm/resources/AuthCookieManager.js.map +1 -0
- package/dist/esm/resources/Base.js +101 -0
- package/dist/esm/resources/Base.js.map +1 -0
- package/dist/esm/resources/Error.js +9 -0
- package/dist/esm/resources/Error.js.map +1 -0
- package/dist/esm/resources/SignIn.js +208 -0
- package/dist/esm/resources/SignIn.js.map +1 -0
- package/dist/esm/resources/SignUp.js +19 -0
- package/dist/esm/resources/SignUp.js.map +1 -0
- package/dist/esm/resources/index.js +2 -0
- package/dist/esm/resources/index.js.map +1 -0
- package/dist/esm/resources/internal.js +7 -0
- package/dist/esm/resources/internal.js.map +1 -0
- package/dist/esm/utils/construct.js +143 -0
- package/dist/esm/utils/construct.js.map +1 -0
- package/dist/esm/utils/index.js +3 -0
- package/dist/esm/utils/index.js.map +1 -0
- package/dist/esm/utils/querystring.js +45 -0
- package/dist/esm/utils/querystring.js.map +1 -0
- package/dist/types/index.d.ts +9 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/instance/TernAuth.d.ts +62 -0
- package/dist/types/instance/TernAuth.d.ts.map +1 -0
- package/dist/types/instance/TernAuthServer.d.ts +32 -0
- package/dist/types/instance/TernAuthServer.d.ts.map +1 -0
- package/dist/types/instance/coreApiClient.d.ts +65 -0
- package/dist/types/instance/coreApiClient.d.ts.map +1 -0
- package/dist/types/instance/coreApiClient.example.d.ts +8 -0
- package/dist/types/instance/coreApiClient.example.d.ts.map +1 -0
- package/dist/types/instance/events.d.ts +27 -0
- package/dist/types/instance/events.d.ts.map +1 -0
- package/dist/types/resources/AuthCookieManager.d.ts +26 -0
- package/dist/types/resources/AuthCookieManager.d.ts.map +1 -0
- package/dist/types/resources/Base.d.ts +40 -0
- package/dist/types/resources/Base.d.ts.map +1 -0
- package/dist/types/resources/Error.d.ts +2 -0
- package/dist/types/resources/Error.d.ts.map +1 -0
- package/dist/types/resources/SignIn.d.ts +32 -0
- package/dist/types/resources/SignIn.d.ts.map +1 -0
- package/dist/types/resources/SignUp.d.ts +14 -0
- package/dist/types/resources/SignUp.d.ts.map +1 -0
- package/dist/types/resources/index.d.ts +2 -0
- package/dist/types/resources/index.d.ts.map +1 -0
- package/dist/types/resources/internal.d.ts +8 -0
- package/dist/types/resources/internal.d.ts.map +1 -0
- package/dist/types/utils/construct.d.ts +67 -0
- package/dist/types/utils/construct.d.ts.map +1 -0
- package/dist/types/utils/index.d.ts +3 -0
- package/dist/types/utils/index.d.ts.map +1 -0
- package/dist/types/utils/querystring.d.ts +7 -0
- package/dist/types/utils/querystring.d.ts.map +1 -0
- package/package.json +50 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var index_exports = {};
|
|
20
|
+
__export(index_exports, {
|
|
21
|
+
CoreApiClient: () => import_coreApiClient.CoreApiClient,
|
|
22
|
+
SignIn: () => import_internal.SignIn,
|
|
23
|
+
TernSecureAuth: () => import_TernAuth.TernSecureAuth,
|
|
24
|
+
TernSecureBase: () => import_internal.TernSecureBase,
|
|
25
|
+
TernServerAuth: () => import_TernAuthServer.TernServerAuth,
|
|
26
|
+
coreApiClient: () => import_coreApiClient.coreApiClient
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(index_exports);
|
|
29
|
+
var import_TernAuth = require("./instance/TernAuth");
|
|
30
|
+
var import_TernAuthServer = require("./instance/TernAuthServer");
|
|
31
|
+
var import_coreApiClient = require("./instance/coreApiClient");
|
|
32
|
+
var import_internal = require("./resources/internal");
|
|
33
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
34
|
+
0 && (module.exports = {
|
|
35
|
+
CoreApiClient,
|
|
36
|
+
SignIn,
|
|
37
|
+
TernSecureAuth,
|
|
38
|
+
TernSecureBase,
|
|
39
|
+
TernServerAuth,
|
|
40
|
+
coreApiClient
|
|
41
|
+
});
|
|
42
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export { TernSecureAuth } from './instance/TernAuth';\nexport type { TernAuth } from './instance/TernAuth';\nexport { TernServerAuth } from './instance/TernAuthServer';\nexport type { TernServerAuthOptions, AuthenticatedApp } from './instance/TernAuthServer';\n\nexport { CoreApiClient, coreApiClient } from './instance/coreApiClient';\nexport type { \n ApiResponse, \n ApiResponseJSON, \n RequestOptions,\n BeforeRequestHook,\n AfterResponseHook\n} from './instance/coreApiClient';\n\nexport { SignIn, TernSecureBase } from './resources/internal';\n\nexport type {\n TernSecureConfig,\n SignInFormValuesTree,\n SignInResponseTree,\n ResendEmailVerification,\n TernSecureUser,\n TernSecureState\n} from '@tern-secure/types';"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAA+B;AAE/B,4BAA+B;AAG/B,2BAA6C;AAS7C,sBAAuC;","names":[]}
|
|
@@ -0,0 +1,471 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var TernAuth_exports = {};
|
|
20
|
+
__export(TernAuth_exports, {
|
|
21
|
+
TernSecureAuth: () => TernSecureAuth,
|
|
22
|
+
inBrowser: () => inBrowser
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(TernAuth_exports);
|
|
25
|
+
var import_errors = require("@tern-secure/shared/errors");
|
|
26
|
+
var import_ternStatusEvent = require("@tern-secure/shared/ternStatusEvent");
|
|
27
|
+
var import_url = require("@tern-secure/shared/url");
|
|
28
|
+
var import_utils = require("@tern-secure/shared/utils");
|
|
29
|
+
var import_app = require("firebase/app");
|
|
30
|
+
var import_auth = require("firebase/auth");
|
|
31
|
+
var import_web_extension = require("firebase/auth/web-extension");
|
|
32
|
+
var import_installations = require("firebase/installations");
|
|
33
|
+
var import_internal = require("../resources/internal");
|
|
34
|
+
var import_construct = require("../utils/construct");
|
|
35
|
+
var import_events = require("./events");
|
|
36
|
+
function inBrowser() {
|
|
37
|
+
return typeof window !== "undefined";
|
|
38
|
+
}
|
|
39
|
+
class TernSecureAuth {
|
|
40
|
+
static version = "1.0.0";
|
|
41
|
+
static sdkMetadata = {
|
|
42
|
+
name: "@tern-secure/auth",
|
|
43
|
+
version: "1.0.0",
|
|
44
|
+
environment: process.env.NODE_ENV || "production"
|
|
45
|
+
};
|
|
46
|
+
static instance = null;
|
|
47
|
+
_currentUser = null;
|
|
48
|
+
signedInSession = null;
|
|
49
|
+
firebaseClientApp;
|
|
50
|
+
authStateUnsubscribe = null;
|
|
51
|
+
auth;
|
|
52
|
+
csrfToken;
|
|
53
|
+
isLoading = false;
|
|
54
|
+
error = null;
|
|
55
|
+
user = null;
|
|
56
|
+
__internal_country;
|
|
57
|
+
#domain;
|
|
58
|
+
#apiUrl;
|
|
59
|
+
#instanceType;
|
|
60
|
+
#status = "loading";
|
|
61
|
+
#listeners = [];
|
|
62
|
+
#options = {};
|
|
63
|
+
#authCookieManager;
|
|
64
|
+
#publicEventBus = (0, import_ternStatusEvent.createTernAuthEventBus)();
|
|
65
|
+
signIn;
|
|
66
|
+
signUp;
|
|
67
|
+
get isReady() {
|
|
68
|
+
return this.status === "ready";
|
|
69
|
+
}
|
|
70
|
+
get status() {
|
|
71
|
+
return this.#status;
|
|
72
|
+
}
|
|
73
|
+
get version() {
|
|
74
|
+
return TernSecureAuth.version;
|
|
75
|
+
}
|
|
76
|
+
set sdkMetadata(metadata) {
|
|
77
|
+
TernSecureAuth.sdkMetadata = metadata;
|
|
78
|
+
}
|
|
79
|
+
get sdkMetadata() {
|
|
80
|
+
return TernSecureAuth.sdkMetadata;
|
|
81
|
+
}
|
|
82
|
+
get requiresVerification() {
|
|
83
|
+
return this.#options.requiresVerification ?? true;
|
|
84
|
+
}
|
|
85
|
+
get apiUrl() {
|
|
86
|
+
return this.#apiUrl;
|
|
87
|
+
}
|
|
88
|
+
getApiUrl = () => this.#apiUrl;
|
|
89
|
+
get domain() {
|
|
90
|
+
if (inBrowser()) {
|
|
91
|
+
const strippedDomainString = (0, import_url.stripScheme)(
|
|
92
|
+
(0, import_utils.handleValueOrFn)(this.#domain, new URL(window.location.href))
|
|
93
|
+
);
|
|
94
|
+
if (this.#instanceType === "production") {
|
|
95
|
+
return strippedDomainString;
|
|
96
|
+
}
|
|
97
|
+
return strippedDomainString;
|
|
98
|
+
}
|
|
99
|
+
return "";
|
|
100
|
+
}
|
|
101
|
+
get instanceType() {
|
|
102
|
+
return this.#instanceType;
|
|
103
|
+
}
|
|
104
|
+
constructor(options) {
|
|
105
|
+
var _a;
|
|
106
|
+
this.#domain = (_a = options == null ? void 0 : options.ternSecureConfig) == null ? void 0 : _a.authDomain;
|
|
107
|
+
this.#apiUrl = (options == null ? void 0 : options.apiUrl) || "";
|
|
108
|
+
this.#instanceType = process.env.NODE_ENV || "production";
|
|
109
|
+
this.#publicEventBus.emit(import_ternStatusEvent.ternEvents.Status, "loading");
|
|
110
|
+
import_internal.TernSecureBase.ternsecure = this;
|
|
111
|
+
}
|
|
112
|
+
setLoading(isLoading) {
|
|
113
|
+
this.isLoading = isLoading;
|
|
114
|
+
}
|
|
115
|
+
authCookieManager() {
|
|
116
|
+
return this.#authCookieManager;
|
|
117
|
+
}
|
|
118
|
+
static getorCreateInstance(options) {
|
|
119
|
+
if (!this.instance) {
|
|
120
|
+
this.instance = new TernSecureAuth(options);
|
|
121
|
+
}
|
|
122
|
+
console.log("[TernSecureAuth] TernSecureAuth instance:", this.instance);
|
|
123
|
+
return this.instance;
|
|
124
|
+
}
|
|
125
|
+
static clearInstance() {
|
|
126
|
+
if (TernSecureAuth.instance) {
|
|
127
|
+
if (TernSecureAuth.instance.authStateUnsubscribe) {
|
|
128
|
+
TernSecureAuth.instance.authStateUnsubscribe();
|
|
129
|
+
TernSecureAuth.instance.authStateUnsubscribe = null;
|
|
130
|
+
}
|
|
131
|
+
TernSecureAuth.instance = null;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
static initialize(options) {
|
|
135
|
+
const instance = this.getorCreateInstance(options);
|
|
136
|
+
instance.#initialize(options);
|
|
137
|
+
return instance;
|
|
138
|
+
}
|
|
139
|
+
#initialize = (options) => {
|
|
140
|
+
this.#options = this.#initOptions(options);
|
|
141
|
+
try {
|
|
142
|
+
if (!this.#options.ternSecureConfig) {
|
|
143
|
+
throw new Error("TernSecureConfig is required to initialize TernSecureAuth");
|
|
144
|
+
}
|
|
145
|
+
if (!this.#options.apiUrl) {
|
|
146
|
+
throw new Error("apiUrl is required to initialize TernSecureAuth");
|
|
147
|
+
}
|
|
148
|
+
this.initializeFirebaseApp(this.#options.ternSecureConfig);
|
|
149
|
+
this.authStateUnsubscribe = this.initAuthStateListener();
|
|
150
|
+
this._onIdTokenChanged();
|
|
151
|
+
this.#authCookieManager = new import_internal.AuthCookieManager();
|
|
152
|
+
this.csrfToken = this.#authCookieManager.getCSRFToken();
|
|
153
|
+
this.signIn = new import_internal.SignIn(this.auth, this.csrfToken);
|
|
154
|
+
this.signUp = new import_internal.SignUp(this.auth);
|
|
155
|
+
this.#setStatus("ready");
|
|
156
|
+
this.#publicEventBus.emit(import_ternStatusEvent.ternEvents.Status, "ready");
|
|
157
|
+
return this;
|
|
158
|
+
} catch (error) {
|
|
159
|
+
this.error = error;
|
|
160
|
+
this.#setStatus("error");
|
|
161
|
+
this.#publicEventBus.emit(import_ternStatusEvent.ternEvents.Status, "error");
|
|
162
|
+
throw error;
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
initializeFirebaseApp(config) {
|
|
166
|
+
const appName = config.appName || "[DEFAULT]";
|
|
167
|
+
this.firebaseClientApp = (0, import_app.getApps)().length === 0 ? (0, import_app.initializeApp)(config, appName) : (0, import_app.getApps)()[0];
|
|
168
|
+
const persistence = this.#setPersistence();
|
|
169
|
+
const auth = (0, import_auth.initializeAuth)(this.firebaseClientApp, {
|
|
170
|
+
persistence
|
|
171
|
+
});
|
|
172
|
+
this.auth = auth;
|
|
173
|
+
if (config.tenantId) {
|
|
174
|
+
this.auth.tenantId = config.tenantId;
|
|
175
|
+
}
|
|
176
|
+
this.#configureEmulator();
|
|
177
|
+
(0, import_installations.getInstallations)(this.firebaseClientApp);
|
|
178
|
+
}
|
|
179
|
+
signOut = async (options) => {
|
|
180
|
+
const redirectUrl = (options == null ? void 0 : options.redirectUrl) || this.#constructAfterSignOutUrl();
|
|
181
|
+
if (options == null ? void 0 : options.onBeforeSignOut) {
|
|
182
|
+
await options.onBeforeSignOut();
|
|
183
|
+
}
|
|
184
|
+
await this.auth.signOut();
|
|
185
|
+
if (options == null ? void 0 : options.onAfterSignOut) {
|
|
186
|
+
await options.onAfterSignOut();
|
|
187
|
+
}
|
|
188
|
+
if (inBrowser()) {
|
|
189
|
+
window.location.href = redirectUrl;
|
|
190
|
+
}
|
|
191
|
+
import_events.eventBus.emit(import_events.events.UserSignOut, null);
|
|
192
|
+
import_events.eventBus.emit(import_events.events.TokenRefreshed, { token: null });
|
|
193
|
+
this.#emit();
|
|
194
|
+
};
|
|
195
|
+
get currentSession() {
|
|
196
|
+
return this.signedInSession;
|
|
197
|
+
}
|
|
198
|
+
initAuthStateListener() {
|
|
199
|
+
return (0, import_auth.onAuthStateChanged)(this.auth, async (user) => {
|
|
200
|
+
await this.auth.authStateReady();
|
|
201
|
+
this._currentUser = user;
|
|
202
|
+
await this.updateCurrentSession();
|
|
203
|
+
import_events.eventBus.emit(import_events.events.UserChanged, this._currentUser);
|
|
204
|
+
this.#emit();
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
_onIdTokenChanged() {
|
|
208
|
+
return (0, import_auth.onIdTokenChanged)(this.auth, async (user) => {
|
|
209
|
+
await this.auth.authStateReady();
|
|
210
|
+
this._currentUser = user;
|
|
211
|
+
await this.updateCurrentSession();
|
|
212
|
+
import_events.eventBus.emit(import_events.events.TokenRefreshed, { token: user ? await user.getIdTokenResult() : null });
|
|
213
|
+
this.#emit();
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
onAuthStateChanged(callback) {
|
|
217
|
+
return (0, import_auth.onAuthStateChanged)(this.auth, callback);
|
|
218
|
+
}
|
|
219
|
+
onIdTokenChanged(callback) {
|
|
220
|
+
return (0, import_auth.onIdTokenChanged)(this.auth, callback);
|
|
221
|
+
}
|
|
222
|
+
async updateCurrentSession() {
|
|
223
|
+
if (!this._currentUser) {
|
|
224
|
+
this.signedInSession = null;
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
try {
|
|
228
|
+
const res = await this._currentUser.getIdTokenResult();
|
|
229
|
+
this.signedInSession = {
|
|
230
|
+
status: "active",
|
|
231
|
+
token: res.token,
|
|
232
|
+
claims: res.claims,
|
|
233
|
+
issuedAtTime: res.issuedAtTime,
|
|
234
|
+
expirationTime: res.expirationTime,
|
|
235
|
+
authTime: res.authTime,
|
|
236
|
+
signInProvider: res.signInProvider || "unknown"
|
|
237
|
+
};
|
|
238
|
+
} catch (error) {
|
|
239
|
+
console.error("[TernSecureAuth] Error updating session:", error);
|
|
240
|
+
this.signedInSession = null;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
async checkRedirectResult() {
|
|
244
|
+
try {
|
|
245
|
+
const result = await (0, import_auth.getRedirectResult)(this.auth);
|
|
246
|
+
if (result) {
|
|
247
|
+
return {
|
|
248
|
+
success: true,
|
|
249
|
+
user: result.user
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
return null;
|
|
253
|
+
} catch (error) {
|
|
254
|
+
const authError = (0, import_errors.handleFirebaseAuthError)(error);
|
|
255
|
+
return {
|
|
256
|
+
success: false,
|
|
257
|
+
message: authError.message,
|
|
258
|
+
error: authError.code,
|
|
259
|
+
user: null
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
addListener = (listener) => {
|
|
264
|
+
this.#listeners.push(listener);
|
|
265
|
+
if (this._currentUser) {
|
|
266
|
+
listener({
|
|
267
|
+
user: this._currentUser,
|
|
268
|
+
session: this.signedInSession
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
const unsubscribe = () => {
|
|
272
|
+
this.#listeners = this.#listeners.filter((l) => l !== listener);
|
|
273
|
+
};
|
|
274
|
+
return unsubscribe;
|
|
275
|
+
};
|
|
276
|
+
on = (...args) => {
|
|
277
|
+
this.#publicEventBus.on(...args);
|
|
278
|
+
};
|
|
279
|
+
off = (...args) => {
|
|
280
|
+
this.#publicEventBus.off(...args);
|
|
281
|
+
};
|
|
282
|
+
initialize(options) {
|
|
283
|
+
this._initialize(options);
|
|
284
|
+
return Promise.resolve();
|
|
285
|
+
}
|
|
286
|
+
static create(options) {
|
|
287
|
+
const instance = this.getorCreateInstance();
|
|
288
|
+
instance.initialize(options);
|
|
289
|
+
return instance;
|
|
290
|
+
}
|
|
291
|
+
_initialize = (options) => {
|
|
292
|
+
this.#options = this.#initOptions(options);
|
|
293
|
+
try {
|
|
294
|
+
if (!this.#options.ternSecureConfig) {
|
|
295
|
+
throw new Error("TernSecureConfig is required to initialize TernSecureAuth");
|
|
296
|
+
}
|
|
297
|
+
if (!this.#options.apiUrl) {
|
|
298
|
+
throw new Error("apiUrl is required to initialize TernSecureAuth");
|
|
299
|
+
}
|
|
300
|
+
this.#apiUrl = this.#options.apiUrl;
|
|
301
|
+
this.initializeFirebaseApp(this.#options.ternSecureConfig);
|
|
302
|
+
this.signIn = new import_internal.SignIn(this.auth, this.csrfToken);
|
|
303
|
+
this.signUp = new import_internal.SignUp(this.auth);
|
|
304
|
+
this.#setStatus("ready");
|
|
305
|
+
} catch (error) {
|
|
306
|
+
this.error = error;
|
|
307
|
+
this.#setStatus("error");
|
|
308
|
+
throw error;
|
|
309
|
+
}
|
|
310
|
+
};
|
|
311
|
+
constructUrlWithAuthRedirect = (to) => {
|
|
312
|
+
const baseUrl = window.location.origin;
|
|
313
|
+
const url = new URL(to, baseUrl);
|
|
314
|
+
if (url.origin === window.location.origin) {
|
|
315
|
+
return url.href;
|
|
316
|
+
}
|
|
317
|
+
return url.toString();
|
|
318
|
+
};
|
|
319
|
+
#buildUrl = (key, options) => {
|
|
320
|
+
var _a, _b;
|
|
321
|
+
if (!key || !this.isReady) {
|
|
322
|
+
return "";
|
|
323
|
+
}
|
|
324
|
+
const baseUrlConfig = key === "signInUrl" ? this.#options.signInUrl : this.#options.signUpUrl;
|
|
325
|
+
const defaultPagePath = key === "signInUrl" ? "/sign-in" : "/sign-up";
|
|
326
|
+
const base = baseUrlConfig || defaultPagePath;
|
|
327
|
+
let effectiveRedirectUrl;
|
|
328
|
+
if (key === "signInUrl" && "signInForceRedirectUrl" in options) {
|
|
329
|
+
effectiveRedirectUrl = options.signInForceRedirectUrl;
|
|
330
|
+
} else if (key === "signUpUrl" && "signUpForceRedirectUrl" in options) {
|
|
331
|
+
effectiveRedirectUrl = options.signUpForceRedirectUrl;
|
|
332
|
+
}
|
|
333
|
+
if (!effectiveRedirectUrl && inBrowser()) {
|
|
334
|
+
const currentUrlParams = new URLSearchParams(window.location.search);
|
|
335
|
+
const existingRedirectParam = currentUrlParams.get("redirect_url");
|
|
336
|
+
if (existingRedirectParam) {
|
|
337
|
+
effectiveRedirectUrl = existingRedirectParam;
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
if (!effectiveRedirectUrl && inBrowser()) {
|
|
341
|
+
effectiveRedirectUrl = window.location.pathname + window.location.search + window.location.hash;
|
|
342
|
+
}
|
|
343
|
+
if (effectiveRedirectUrl && inBrowser()) {
|
|
344
|
+
let signInPagePath;
|
|
345
|
+
try {
|
|
346
|
+
signInPagePath = this.#options.signInUrl ? new URL(this.#options.signInUrl, window.location.origin).pathname : defaultPagePath;
|
|
347
|
+
} catch {
|
|
348
|
+
signInPagePath = defaultPagePath;
|
|
349
|
+
}
|
|
350
|
+
let signUpPagePath;
|
|
351
|
+
try {
|
|
352
|
+
signUpPagePath = this.#options.signUpUrl ? new URL(this.#options.signUpUrl, window.location.origin).pathname : key === "signUpUrl" ? defaultPagePath : "/sign-in";
|
|
353
|
+
} catch {
|
|
354
|
+
signUpPagePath = key === "signUpUrl" ? defaultPagePath : "/sign-in";
|
|
355
|
+
}
|
|
356
|
+
const redirectTargetObj = new URL(effectiveRedirectUrl, window.location.origin);
|
|
357
|
+
if (redirectTargetObj.pathname === signInPagePath || redirectTargetObj.pathname === signUpPagePath) {
|
|
358
|
+
effectiveRedirectUrl = "/";
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
const paramsForBuildUrl = {
|
|
362
|
+
base,
|
|
363
|
+
searchParams: new URLSearchParams()
|
|
364
|
+
};
|
|
365
|
+
if (effectiveRedirectUrl) {
|
|
366
|
+
if (inBrowser()) {
|
|
367
|
+
const absoluteRedirectUrl = new URL(effectiveRedirectUrl, window.location.origin).href;
|
|
368
|
+
(_a = paramsForBuildUrl.searchParams) == null ? void 0 : _a.set("redirect", absoluteRedirectUrl);
|
|
369
|
+
} else {
|
|
370
|
+
(_b = paramsForBuildUrl.searchParams) == null ? void 0 : _b.set("redirect", effectiveRedirectUrl);
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
const constructedUrl = (0, import_construct.buildURL)(paramsForBuildUrl, {
|
|
374
|
+
stringify: true,
|
|
375
|
+
skipOrigin: false
|
|
376
|
+
});
|
|
377
|
+
if (typeof constructedUrl !== "string") {
|
|
378
|
+
console.error(
|
|
379
|
+
"[TernSecure] Error: buildURL did not return a string as expected. Falling back to base URL."
|
|
380
|
+
);
|
|
381
|
+
if (inBrowser()) {
|
|
382
|
+
try {
|
|
383
|
+
return new URL(base, window.location.origin).href;
|
|
384
|
+
} catch {
|
|
385
|
+
return base;
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
return base;
|
|
389
|
+
}
|
|
390
|
+
return this.constructUrlWithAuthRedirect(constructedUrl);
|
|
391
|
+
};
|
|
392
|
+
#constructAfterSignOutUrl = () => {
|
|
393
|
+
if (!this.#options.afterSignOutUrl) {
|
|
394
|
+
return "/";
|
|
395
|
+
}
|
|
396
|
+
return this.constructUrlWithAuthRedirect(this.#options.afterSignOutUrl);
|
|
397
|
+
};
|
|
398
|
+
constructSignInUrl = (options) => {
|
|
399
|
+
return this.#buildUrl("signInUrl", { ...options });
|
|
400
|
+
};
|
|
401
|
+
constructSignUpUrl = (options) => {
|
|
402
|
+
return this.#buildUrl("signUpUrl", { ...options });
|
|
403
|
+
};
|
|
404
|
+
__internal_setCountry = (country) => {
|
|
405
|
+
if (!this.__internal_country) {
|
|
406
|
+
this.__internal_country = country;
|
|
407
|
+
}
|
|
408
|
+
};
|
|
409
|
+
#initOptions = (options) => {
|
|
410
|
+
return {
|
|
411
|
+
...options
|
|
412
|
+
};
|
|
413
|
+
};
|
|
414
|
+
#emit = () => {
|
|
415
|
+
if (this._currentUser) {
|
|
416
|
+
for (const listener of this.#listeners) {
|
|
417
|
+
listener({
|
|
418
|
+
user: this._currentUser
|
|
419
|
+
});
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
};
|
|
423
|
+
#setStatus(newStatus) {
|
|
424
|
+
if (this.#status !== newStatus) {
|
|
425
|
+
this.#status = newStatus;
|
|
426
|
+
this.#publicEventBus.emit(import_ternStatusEvent.ternEvents.Status, this.#status);
|
|
427
|
+
if (newStatus === "ready") {
|
|
428
|
+
this.#publicEventBus.emit(import_ternStatusEvent.ternEvents.Status, "ready");
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
#setPersistence = () => {
|
|
433
|
+
const persistenceType = this.#options.persistence || "none";
|
|
434
|
+
switch (persistenceType) {
|
|
435
|
+
case "browserCookie":
|
|
436
|
+
return import_web_extension.browserCookiePersistence;
|
|
437
|
+
case "session":
|
|
438
|
+
return import_auth.browserSessionPersistence;
|
|
439
|
+
case "local":
|
|
440
|
+
return import_auth.browserLocalPersistence;
|
|
441
|
+
case "none":
|
|
442
|
+
default:
|
|
443
|
+
return import_auth.inMemoryPersistence;
|
|
444
|
+
}
|
|
445
|
+
};
|
|
446
|
+
#emulatorHost = () => {
|
|
447
|
+
if (typeof process === "undefined") return void 0;
|
|
448
|
+
return process.env.FIREBASE_AUTH_EMULATOR_HOST;
|
|
449
|
+
};
|
|
450
|
+
#configureEmulator = () => {
|
|
451
|
+
const host = this.#emulatorHost();
|
|
452
|
+
const isDev = this.#instanceType === "development";
|
|
453
|
+
const shouldUseEmulator = isDev && !!host;
|
|
454
|
+
if (!shouldUseEmulator || !host) {
|
|
455
|
+
return;
|
|
456
|
+
}
|
|
457
|
+
const emulatorUrl = host.startsWith("http") ? host : `http://${host}`;
|
|
458
|
+
try {
|
|
459
|
+
(0, import_auth.connectAuthEmulator)(this.auth, emulatorUrl, { disableWarnings: true });
|
|
460
|
+
console.warn(`[TernSecure] Firebase Auth Emulator connected at ${emulatorUrl}`);
|
|
461
|
+
} catch (error) {
|
|
462
|
+
console.error("[TernSecure] Error connecting to Firebase Auth Emulator:", error);
|
|
463
|
+
}
|
|
464
|
+
};
|
|
465
|
+
}
|
|
466
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
467
|
+
0 && (module.exports = {
|
|
468
|
+
TernSecureAuth,
|
|
469
|
+
inBrowser
|
|
470
|
+
});
|
|
471
|
+
//# sourceMappingURL=TernAuth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/instance/TernAuth.ts"],"sourcesContent":["import { handleFirebaseAuthError } from '@tern-secure/shared/errors';\nimport { createTernAuthEventBus, ternEvents } from '@tern-secure/shared/ternStatusEvent';\nimport { stripScheme } from '@tern-secure/shared/url';\nimport { handleValueOrFn } from '@tern-secure/shared/utils';\nimport type {\n DomainOrProxyUrl,\n InstanceType,\n ListenerCallback,\n RedirectOptions,\n SignedInSession,\n SignInRedirectOptions,\n SignInResource,\n SignInResponseTree,\n SignOut,\n SignOutOptions,\n SignUpRedirectOptions,\n SignUpResource,\n TernSecureAuth as TernSecureAuthInterface,\n TernSecureAuthOptions,\n TernSecureAuthStatus,\n TernSecureConfig,\n TernSecureResources,\n TernSecureSDK,\n TernSecureUser,\n UnsubscribeCallback,\n} from '@tern-secure/types';\nimport type { FirebaseApp } from 'firebase/app';\nimport { getApps, initializeApp } from 'firebase/app';\nimport type { Auth, Auth as TernAuth } from 'firebase/auth';\nimport {\n browserLocalPersistence,\n browserSessionPersistence,\n connectAuthEmulator,\n getRedirectResult,\n initializeAuth,\n inMemoryPersistence,\n onAuthStateChanged,\n onIdTokenChanged,\n} from 'firebase/auth';\nimport { browserCookiePersistence } from 'firebase/auth/web-extension';\nimport { getInstallations } from 'firebase/installations';\n\nimport { AuthCookieManager, SignIn, SignUp, TernSecureBase } from '../resources/internal';\nimport { buildURL } from '../utils/construct';\nimport { eventBus, events } from './events';\n\nexport function inBrowser(): boolean {\n return typeof window !== 'undefined';\n}\n\nexport { TernAuth };\n\n/**\n * Firebase implementation of the TernSecureAuth interface\n */\nexport class TernSecureAuth implements TernSecureAuthInterface {\n public static version: string = PACKAGE_VERSION;\n public static sdkMetadata: TernSecureSDK = {\n name: PACKAGE_NAME,\n version: PACKAGE_VERSION,\n environment: process.env.NODE_ENV || 'production',\n };\n private static instance: TernSecureAuth | null = null;\n private _currentUser: TernSecureUser | null = null;\n private signedInSession: SignedInSession | null = null;\n private firebaseClientApp: FirebaseApp | undefined;\n private authStateUnsubscribe: (() => void) | null = null;\n private auth!: Auth;\n private csrfToken: string | undefined;\n public isLoading = false;\n public error: Error | null = null;\n public user: TernSecureUser | null | undefined = null;\n public __internal_country?: string | null;\n #domain: DomainOrProxyUrl['domain'];\n #apiUrl!: string;\n #instanceType?: InstanceType;\n #status: TernSecureAuthInterface['status'] = 'loading';\n #listeners: Array<(emission: TernSecureResources) => void> = [];\n #options: TernSecureAuthOptions = {} as TernSecureAuthOptions;\n #authCookieManager?: AuthCookieManager;\n #publicEventBus = createTernAuthEventBus();\n\n signIn!: SignInResource;\n signUp!: SignUpResource;\n\n get isReady(): boolean {\n return this.status === 'ready';\n }\n\n get status(): TernSecureAuthInterface['status'] {\n return this.#status;\n }\n\n get version(): string {\n return TernSecureAuth.version;\n }\n\n set sdkMetadata(metadata: TernSecureSDK) {\n TernSecureAuth.sdkMetadata = metadata;\n }\n\n get sdkMetadata(): TernSecureSDK {\n return TernSecureAuth.sdkMetadata;\n }\n\n get requiresVerification(): boolean {\n return this.#options.requiresVerification ?? true;\n }\n\n get apiUrl(): string {\n return this.#apiUrl;\n }\n\n public getApiUrl = (): string => this.#apiUrl;\n\n get domain(): string {\n if (inBrowser()) {\n const strippedDomainString = stripScheme(\n handleValueOrFn(this.#domain, new URL(window.location.href)),\n );\n if (this.#instanceType === 'production') {\n return strippedDomainString;\n }\n return strippedDomainString;\n }\n return '';\n }\n\n get instanceType() {\n return this.#instanceType;\n }\n\n public constructor(options?: TernSecureAuthOptions) {\n this.#domain = options?.ternSecureConfig?.authDomain;\n this.#apiUrl = options?.apiUrl || '';\n this.#instanceType = (process.env.NODE_ENV as InstanceType) || 'production';\n this.#publicEventBus.emit(ternEvents.Status, 'loading');\n TernSecureBase.ternsecure = this;\n }\n\n public setLoading(isLoading: boolean): void {\n this.isLoading = isLoading;\n }\n\n public authCookieManager(): AuthCookieManager | undefined {\n return this.#authCookieManager;\n }\n\n static getorCreateInstance(options?: TernSecureAuthOptions): TernSecureAuth {\n if (!this.instance) {\n this.instance = new TernSecureAuth(options);\n }\n console.log('[TernSecureAuth] TernSecureAuth instance:', this.instance);\n return this.instance;\n }\n\n static clearInstance() {\n if (TernSecureAuth.instance) {\n if (TernSecureAuth.instance.authStateUnsubscribe) {\n TernSecureAuth.instance.authStateUnsubscribe();\n TernSecureAuth.instance.authStateUnsubscribe = null;\n }\n TernSecureAuth.instance = null;\n }\n }\n\n public static initialize(options: TernSecureAuthOptions): TernSecureAuth {\n const instance = this.getorCreateInstance(options);\n instance.#initialize(options);\n return instance;\n }\n\n #initialize = (options: TernSecureAuthOptions): TernSecureAuth => {\n this.#options = this.#initOptions(options);\n\n try {\n if (!this.#options.ternSecureConfig) {\n throw new Error('TernSecureConfig is required to initialize TernSecureAuth');\n }\n\n if (!this.#options.apiUrl) {\n throw new Error('apiUrl is required to initialize TernSecureAuth');\n }\n\n this.initializeFirebaseApp(this.#options.ternSecureConfig);\n this.authStateUnsubscribe = this.initAuthStateListener();\n this._onIdTokenChanged();\n\n this.#authCookieManager = new AuthCookieManager();\n this.csrfToken = this.#authCookieManager.getCSRFToken();\n\n this.signIn = new SignIn(this.auth, this.csrfToken);\n this.signUp = new SignUp(this.auth);\n\n this.#setStatus('ready');\n this.#publicEventBus.emit(ternEvents.Status, 'ready');\n\n return this;\n } catch (error) {\n this.error = error as Error;\n this.#setStatus('error');\n this.#publicEventBus.emit(ternEvents.Status, 'error');\n throw error;\n }\n };\n\n private initializeFirebaseApp(config: TernSecureConfig) {\n const appName = config.appName || '[DEFAULT]';\n this.firebaseClientApp = getApps().length === 0 ? initializeApp(config, appName) : getApps()[0];\n\n const persistence = this.#setPersistence();\n const auth = initializeAuth(this.firebaseClientApp, {\n persistence,\n });\n\n this.auth = auth;\n\n if (config.tenantId) {\n this.auth.tenantId = config.tenantId;\n }\n\n this.#configureEmulator();\n\n getInstallations(this.firebaseClientApp);\n }\n\n public signOut: SignOut = async (options?: SignOutOptions) => {\n const redirectUrl = options?.redirectUrl || this.#constructAfterSignOutUrl();\n if (options?.onBeforeSignOut) {\n await options.onBeforeSignOut();\n }\n\n await this.auth.signOut();\n\n if (options?.onAfterSignOut) {\n await options.onAfterSignOut();\n }\n if (inBrowser()) {\n window.location.href = redirectUrl;\n }\n eventBus.emit(events.UserSignOut, null);\n eventBus.emit(events.TokenRefreshed, { token: null });\n this.#emit();\n };\n\n get currentSession(): SignedInSession | null {\n return this.signedInSession;\n };\n\n private initAuthStateListener(): () => void {\n return onAuthStateChanged(this.auth, async (user: TernSecureUser | null) => {\n await this.auth.authStateReady();\n this._currentUser = user;\n await this.updateCurrentSession();\n\n eventBus.emit(events.UserChanged, this._currentUser);\n this.#emit();\n });\n }\n\n private _onIdTokenChanged(): () => void {\n return onIdTokenChanged(this.auth, async (user: TernSecureUser | null) => {\n await this.auth.authStateReady();\n this._currentUser = user;\n await this.updateCurrentSession();\n\n eventBus.emit(events.TokenRefreshed, { token: user ? await user.getIdTokenResult() : null });\n this.#emit();\n });\n }\n\n public onAuthStateChanged(callback: (cb: any) => void): () => void {\n return onAuthStateChanged(this.auth, callback);\n }\n\n public onIdTokenChanged(callback: (cb: any) => void): () => void {\n return onIdTokenChanged(this.auth, callback);\n }\n\n private async updateCurrentSession(): Promise<void> {\n if (!this._currentUser) {\n this.signedInSession = null;\n return;\n }\n\n try {\n const res = await this._currentUser.getIdTokenResult();\n this.signedInSession = {\n status: 'active',\n token: res.token,\n claims: res.claims,\n issuedAtTime: res.issuedAtTime,\n expirationTime: res.expirationTime,\n authTime: res.authTime,\n signInProvider: res.signInProvider || 'unknown',\n };\n } catch (error) {\n console.error('[TernSecureAuth] Error updating session:', error);\n this.signedInSession = null;\n }\n }\n\n public async checkRedirectResult(): Promise<SignInResponseTree | null> {\n try {\n const result = await getRedirectResult(this.auth);\n if (result) {\n return {\n success: true,\n user: result.user as TernSecureUser,\n };\n }\n return null;\n } catch (error) {\n const authError = handleFirebaseAuthError(error);\n return {\n success: false,\n message: authError.message,\n error: authError.code,\n user: null,\n };\n }\n }\n\n public addListener = (listener: ListenerCallback): UnsubscribeCallback => {\n this.#listeners.push(listener);\n if (this._currentUser) {\n listener({\n user: this._currentUser,\n session: this.signedInSession,\n });\n }\n\n const unsubscribe = () => {\n this.#listeners = this.#listeners.filter(l => l !== listener);\n };\n return unsubscribe;\n };\n\n public on: TernSecureAuthInterface['on'] = (...args) => {\n this.#publicEventBus.on(...args);\n };\n\n public off: TernSecureAuthInterface['off'] = (...args) => {\n this.#publicEventBus.off(...args);\n };\n\n public initialize(options: TernSecureAuthOptions): Promise<void> {\n this._initialize(options);\n return Promise.resolve();\n }\n\n public static create(options: TernSecureAuthOptions): TernSecureAuth {\n const instance = this.getorCreateInstance();\n instance.initialize(options);\n return instance;\n }\n\n _initialize = (options: TernSecureAuthOptions): void => {\n this.#options = this.#initOptions(options);\n try {\n if (!this.#options.ternSecureConfig) {\n throw new Error('TernSecureConfig is required to initialize TernSecureAuth');\n }\n\n if (!this.#options.apiUrl) {\n throw new Error('apiUrl is required to initialize TernSecureAuth');\n }\n\n this.#apiUrl = this.#options.apiUrl;\n\n this.initializeFirebaseApp(this.#options.ternSecureConfig);\n\n this.signIn = new SignIn(this.auth, this.csrfToken);\n this.signUp = new SignUp(this.auth);\n\n this.#setStatus('ready');\n } catch (error) {\n this.error = error as Error;\n this.#setStatus('error');\n throw error;\n }\n };\n\n public constructUrlWithAuthRedirect = (to: string): string => {\n const baseUrl = window.location.origin;\n const url = new URL(to, baseUrl);\n\n if (url.origin === window.location.origin) {\n return url.href;\n }\n\n return url.toString();\n };\n\n #buildUrl = (key: 'signInUrl' | 'signUpUrl', options: RedirectOptions): string => {\n if (!key || !this.isReady) {\n return '';\n }\n\n const baseUrlConfig = key === 'signInUrl' ? this.#options.signInUrl : this.#options.signUpUrl;\n const defaultPagePath = key === 'signInUrl' ? '/sign-in' : '/sign-up';\n const base = baseUrlConfig || defaultPagePath;\n\n let effectiveRedirectUrl: string | null | undefined;\n\n // Priority 1: Get redirect URL from options (signInForceRedirectUrl or signUpForceRedirectUrl)\n if (key === 'signInUrl' && 'signInForceRedirectUrl' in options) {\n effectiveRedirectUrl = options.signInForceRedirectUrl;\n } else if (key === 'signUpUrl' && 'signUpForceRedirectUrl' in options) {\n effectiveRedirectUrl = options.signUpForceRedirectUrl;\n }\n\n // Priority 2: If no force redirect from options, check 'redirect' param in current URL (only in browser)\n if (!effectiveRedirectUrl && inBrowser()) {\n const currentUrlParams = new URLSearchParams(window.location.search);\n const existingRedirectParam = currentUrlParams.get('redirect_url');\n if (existingRedirectParam) {\n effectiveRedirectUrl = existingRedirectParam;\n }\n }\n\n // Priority 3: If still no redirect URL, fallback to current page's full path (only in browser)\n // This ensures that if the call originates from a page, it attempts to redirect back there by default.\n if (!effectiveRedirectUrl && inBrowser()) {\n effectiveRedirectUrl =\n window.location.pathname + window.location.search + window.location.hash;\n }\n\n if (effectiveRedirectUrl && inBrowser()) {\n let signInPagePath: string | undefined;\n try {\n signInPagePath = this.#options.signInUrl\n ? new URL(this.#options.signInUrl, window.location.origin).pathname\n : defaultPagePath;\n } catch {\n signInPagePath = defaultPagePath;\n }\n\n let signUpPagePath: string | undefined;\n try {\n signUpPagePath = this.#options.signUpUrl\n ? new URL(this.#options.signUpUrl, window.location.origin).pathname\n : key === 'signUpUrl'\n ? defaultPagePath\n : '/sign-in';\n } catch {\n signUpPagePath = key === 'signUpUrl' ? defaultPagePath : '/sign-in';\n }\n\n const redirectTargetObj = new URL(effectiveRedirectUrl, window.location.origin);\n\n if (\n redirectTargetObj.pathname === signInPagePath ||\n redirectTargetObj.pathname === signUpPagePath\n ) {\n // If the intended redirect path is the sign-in or sign-up page itself,\n // change the redirect target to the application root ('/').\n effectiveRedirectUrl = '/';\n }\n }\n\n const paramsForBuildUrl: Parameters<typeof buildURL>[0] = {\n base,\n searchParams: new URLSearchParams(),\n };\n\n if (effectiveRedirectUrl) {\n // Check if a redirect URL was determined\n if (inBrowser()) {\n const absoluteRedirectUrl = new URL(effectiveRedirectUrl, window.location.origin).href;\n paramsForBuildUrl.searchParams?.set('redirect', absoluteRedirectUrl);\n } else {\n // If not in browser, use the effectiveRedirectUrl as is.\n // This assumes it's either absolute or a path the server can interpret.\n paramsForBuildUrl.searchParams?.set('redirect', effectiveRedirectUrl);\n }\n }\n\n const constructedUrl = buildURL(paramsForBuildUrl, {\n stringify: true,\n skipOrigin: false,\n });\n\n if (typeof constructedUrl !== 'string') {\n console.error(\n '[TernSecure] Error: buildURL did not return a string as expected. Falling back to base URL.',\n );\n if (inBrowser()) {\n try {\n return new URL(base, window.location.origin).href;\n } catch {\n return base;\n }\n }\n return base;\n }\n\n return this.constructUrlWithAuthRedirect(constructedUrl);\n };\n\n #constructAfterSignOutUrl = (): string => {\n if (!this.#options.afterSignOutUrl) {\n return '/';\n }\n return this.constructUrlWithAuthRedirect(this.#options.afterSignOutUrl);\n };\n\n public constructSignInUrl = (options?: SignInRedirectOptions): string => {\n return this.#buildUrl('signInUrl', { ...options });\n };\n\n public constructSignUpUrl = (options?: SignUpRedirectOptions): string => {\n return this.#buildUrl('signUpUrl', { ...options });\n };\n\n __internal_setCountry = (country: string | null) => {\n if (!this.__internal_country) {\n this.__internal_country = country;\n }\n };\n\n #initOptions = (options: TernSecureAuthOptions): TernSecureAuthOptions => {\n return {\n ...options,\n };\n };\n\n #emit = (): void => {\n if (this._currentUser) {\n for (const listener of this.#listeners) {\n listener({\n user: this._currentUser,\n });\n }\n }\n };\n\n #setStatus(newStatus: TernSecureAuthStatus): void {\n if (this.#status !== newStatus) {\n this.#status = newStatus;\n this.#publicEventBus.emit(ternEvents.Status, this.#status);\n\n if (newStatus === 'ready') {\n this.#publicEventBus.emit(ternEvents.Status, 'ready');\n }\n }\n }\n\n #setPersistence = () => {\n const persistenceType = this.#options.persistence || 'none';\n\n switch (persistenceType) {\n case 'browserCookie':\n return browserCookiePersistence;\n case 'session':\n return browserSessionPersistence;\n case 'local':\n return browserLocalPersistence;\n case 'none':\n default:\n return inMemoryPersistence;\n }\n };\n\n #emulatorHost = (): string | undefined => {\n if (typeof process === 'undefined') return undefined;\n return process.env.FIREBASE_AUTH_EMULATOR_HOST;\n };\n\n #configureEmulator = (): void => {\n const host = this.#emulatorHost();\n const isDev = this.#instanceType === 'development';\n const shouldUseEmulator = isDev && !!host;\n if (!shouldUseEmulator || !host) {\n return;\n }\n\n const emulatorUrl = host.startsWith('http') ? host : `http://${host}`;\n\n try {\n //(this.auth as unknown as any)._canInitEmulator = true;\n connectAuthEmulator(this.auth, emulatorUrl, { disableWarnings: true });\n console.warn(`[TernSecure] Firebase Auth Emulator connected at ${emulatorUrl}`);\n } catch (error) {\n console.error('[TernSecure] Error connecting to Firebase Auth Emulator:', error);\n }\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAwC;AACxC,6BAAmD;AACnD,iBAA4B;AAC5B,mBAAgC;AAwBhC,iBAAuC;AAEvC,kBASO;AACP,2BAAyC;AACzC,2BAAiC;AAEjC,sBAAkE;AAClE,uBAAyB;AACzB,oBAAiC;AAE1B,SAAS,YAAqB;AACnC,SAAO,OAAO,WAAW;AAC3B;AAOO,MAAM,eAAkD;AAAA,EAC7D,OAAc,UAAkB;AAAA,EAChC,OAAc,cAA6B;AAAA,IACzC,MAAM;AAAA,IACN,SAAS;AAAA,IACT,aAAa,QAAQ,IAAI,YAAY;AAAA,EACvC;AAAA,EACA,OAAe,WAAkC;AAAA,EACzC,eAAsC;AAAA,EACtC,kBAA0C;AAAA,EAC1C;AAAA,EACA,uBAA4C;AAAA,EAC5C;AAAA,EACA;AAAA,EACD,YAAY;AAAA,EACZ,QAAsB;AAAA,EACtB,OAA0C;AAAA,EAC1C;AAAA,EACP;AAAA,EACA;AAAA,EACA;AAAA,EACA,UAA6C;AAAA,EAC7C,aAA6D,CAAC;AAAA,EAC9D,WAAkC,CAAC;AAAA,EACnC;AAAA,EACA,sBAAkB,+CAAuB;AAAA,EAEzC;AAAA,EACA;AAAA,EAEA,IAAI,UAAmB;AACrB,WAAO,KAAK,WAAW;AAAA,EACzB;AAAA,EAEA,IAAI,SAA4C;AAC9C,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,IAAI,UAAkB;AACpB,WAAO,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AuC;AAChD,QAAI,KAAK,YAAY,WAAW;AAC9B,WAAK,UAAU;AACf,WAAK,gBAAgB,KAAK,kCAAW,QAAQ,KAAK,OAAO;AAEzD,UAAI,cAAc,SAAS;AACzB,aAAK,gBAAgB,KAAK,kCAAW,QAAQ,OAAO;AAAA,MACtD;AAAA,IACF;AAAA,EACF;AAAA,EAEA,kBAAkB,MAAM;AACtB,UAAM,kBAAkB,KAAK,SAAS,eAAe;AAErD,YAAQ,iBAAiB;AAAA,MACvB,KAAK;AACH,eAAO;AAAA,MACT,KAAK;AACH,eAAO;AAAA,MACT,KAAK;AACH,eAAO;AAAA,MACT,KAAK;AAAA,MACL;AACE,eAAO;AAAA,IACX;AAAA,EACF;AAAA,EAEA,gBAAgB,MAA0B;AACxC,QAAI,OAAO,YAAY,YAAa,QAAO;AAC3C,WAAO,QAAQ,IAAI;AAAA,EACrB;AAAA,EAEA,qBAAqB,MAAY;AAC/B,UAAM,OAAO,KAAK,cAAc;AAChC,UAAM,QAAQ,KAAK,kBAAkB;AACrC,UAAM,oBAAoB,SAAS,CAAC,CAAC;AACrC,QAAI,CAAC,qBAAqB,CAAC,MAAM;AAC/B;AAAA,IACF;AAEA,UAAM,cAAc,KAAK,WAAW,MAAM,IAAI,OAAO,UAAU,IAAI;AAEnE,QAAI;AAEF,2CAAoB,KAAK,MAAM,aAAa,EAAE,iBAAiB,KAAK,CAAC;AACrE,cAAQ,KAAK,oDAAoD,WAAW,EAAE;AAAA,IAChF,SAAS,OAAO;AACd,cAAQ,MAAM,4DAA4D,KAAK;AAAA,IACjF;AAAA,EACF;AACF;","names":[]}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var TernAuthServer_exports = {};
|
|
20
|
+
__export(TernAuthServer_exports, {
|
|
21
|
+
TernServerAuth: () => TernServerAuth
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(TernAuthServer_exports);
|
|
24
|
+
var import_app = require("firebase/app");
|
|
25
|
+
var import_auth = require("firebase/auth");
|
|
26
|
+
class TernServerAuth {
|
|
27
|
+
static instance = null;
|
|
28
|
+
auth;
|
|
29
|
+
#options = {};
|
|
30
|
+
constructor() {
|
|
31
|
+
}
|
|
32
|
+
static getInstance() {
|
|
33
|
+
if (!this.instance) {
|
|
34
|
+
this.instance = new TernServerAuth();
|
|
35
|
+
}
|
|
36
|
+
return this.instance;
|
|
37
|
+
}
|
|
38
|
+
static initialize(options) {
|
|
39
|
+
const instance = this.getInstance();
|
|
40
|
+
instance.#initialize(options);
|
|
41
|
+
return instance;
|
|
42
|
+
}
|
|
43
|
+
#initialize(options) {
|
|
44
|
+
this.#options = this.#initOptions(options);
|
|
45
|
+
}
|
|
46
|
+
static clearInstance() {
|
|
47
|
+
this.instance = null;
|
|
48
|
+
}
|
|
49
|
+
getAuthIdToken = async () => {
|
|
50
|
+
await this.auth.authStateReady();
|
|
51
|
+
if (!this.auth.currentUser) return;
|
|
52
|
+
return await (0, import_auth.getIdToken)(this.auth.currentUser);
|
|
53
|
+
};
|
|
54
|
+
getAuthenticatedAppFromHeaders = async (headers) => {
|
|
55
|
+
const authHeader = headers.get("Authorization");
|
|
56
|
+
const idToken = authHeader == null ? void 0 : authHeader.split("Bearer ")[1];
|
|
57
|
+
let appSettings = {};
|
|
58
|
+
appSettings = {
|
|
59
|
+
releaseOnDeref: headers
|
|
60
|
+
};
|
|
61
|
+
if (idToken && idToken.trim()) {
|
|
62
|
+
appSettings.authIdToken = idToken;
|
|
63
|
+
}
|
|
64
|
+
return this.getServerApp(appSettings);
|
|
65
|
+
};
|
|
66
|
+
getServerApp = async (appSettings) => {
|
|
67
|
+
const firebaseServerConfig = this.#options.firebaseServerConfig;
|
|
68
|
+
if (!firebaseServerConfig) {
|
|
69
|
+
throw new Error(
|
|
70
|
+
"Firebase server configuration is required to initialize the server app"
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
const firebaseServerApp = (0, import_app.initializeServerApp)(
|
|
74
|
+
firebaseServerConfig,
|
|
75
|
+
appSettings || {}
|
|
76
|
+
);
|
|
77
|
+
this.auth = (0, import_auth.getAuth)(firebaseServerApp);
|
|
78
|
+
await this.auth.authStateReady();
|
|
79
|
+
return {
|
|
80
|
+
firebaseServerApp,
|
|
81
|
+
currentUser: this.auth.currentUser,
|
|
82
|
+
auth: this.auth
|
|
83
|
+
};
|
|
84
|
+
};
|
|
85
|
+
#initOptions = (options) => {
|
|
86
|
+
return {
|
|
87
|
+
...options
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
92
|
+
0 && (module.exports = {
|
|
93
|
+
TernServerAuth
|
|
94
|
+
});
|
|
95
|
+
//# sourceMappingURL=TernAuthServer.js.map
|