@marcwelti/mw-core 0.2.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/README.md +141 -0
- package/dist/context/index.d.mts +95 -0
- package/dist/context/index.d.ts +95 -0
- package/dist/context/index.js +280 -0
- package/dist/context/index.js.map +1 -0
- package/dist/context/index.mjs +276 -0
- package/dist/context/index.mjs.map +1 -0
- package/dist/firebase/index.d.mts +176 -0
- package/dist/firebase/index.d.ts +176 -0
- package/dist/firebase/index.js +393 -0
- package/dist/firebase/index.js.map +1 -0
- package/dist/firebase/index.mjs +318 -0
- package/dist/firebase/index.mjs.map +1 -0
- package/dist/hooks/index.d.mts +97 -0
- package/dist/hooks/index.d.ts +97 -0
- package/dist/hooks/index.js +618 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/hooks/index.mjs +611 -0
- package/dist/hooks/index.mjs.map +1 -0
- package/dist/index.d.mts +12 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +922 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +843 -0
- package/dist/index.mjs.map +1 -0
- package/dist/server/index.d.mts +216 -0
- package/dist/server/index.d.ts +216 -0
- package/dist/server/index.js +309 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/index.mjs +276 -0
- package/dist/server/index.mjs.map +1 -0
- package/dist/storage-BU_rfYCi.d.mts +43 -0
- package/dist/storage-BU_rfYCi.d.ts +43 -0
- package/dist/types/index.d.mts +108 -0
- package/dist/types/index.d.ts +108 -0
- package/dist/types/index.js +12 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/index.mjs +3 -0
- package/dist/types/index.mjs.map +1 -0
- package/package.json +91 -0
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
import { createContext, useState, useEffect, useCallback, useMemo, useContext } from 'react';
|
|
2
|
+
import { getAuth, onAuthStateChanged, signInWithEmailAndPassword, createUserWithEmailAndPassword, updateProfile, signOut as signOut$1, GoogleAuthProvider, signInWithPopup, sendPasswordResetEmail, sendEmailVerification } from 'firebase/auth';
|
|
3
|
+
import { getApps, getApp, initializeApp } from 'firebase/app';
|
|
4
|
+
import { getFirestore } from 'firebase/firestore';
|
|
5
|
+
import { getStorage } from 'firebase/storage';
|
|
6
|
+
import { jsx, Fragment } from 'react/jsx-runtime';
|
|
7
|
+
|
|
8
|
+
// src/context/AuthContext.tsx
|
|
9
|
+
function getFirebaseConfig() {
|
|
10
|
+
const config = {
|
|
11
|
+
apiKey: process.env.NEXT_PUBLIC_FIREBASE_API_KEY || "",
|
|
12
|
+
authDomain: process.env.NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN || "",
|
|
13
|
+
projectId: process.env.NEXT_PUBLIC_FIREBASE_PROJECT_ID || "",
|
|
14
|
+
storageBucket: process.env.NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET || "",
|
|
15
|
+
messagingSenderId: process.env.NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID || "",
|
|
16
|
+
appId: process.env.NEXT_PUBLIC_FIREBASE_APP_ID || "",
|
|
17
|
+
measurementId: process.env.NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID
|
|
18
|
+
};
|
|
19
|
+
const requiredFields = [
|
|
20
|
+
"apiKey",
|
|
21
|
+
"authDomain",
|
|
22
|
+
"projectId",
|
|
23
|
+
"storageBucket",
|
|
24
|
+
"messagingSenderId",
|
|
25
|
+
"appId"
|
|
26
|
+
];
|
|
27
|
+
const missingFields = requiredFields.filter((field) => !config[field]);
|
|
28
|
+
if (missingFields.length > 0) {
|
|
29
|
+
console.warn(
|
|
30
|
+
`[mw-core] Missing Firebase config fields: ${missingFields.join(", ")}. Make sure to set NEXT_PUBLIC_FIREBASE_* environment variables.`
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
return config;
|
|
34
|
+
}
|
|
35
|
+
function initializeFirebase(config) {
|
|
36
|
+
if (getApps().length > 0) {
|
|
37
|
+
return getApp();
|
|
38
|
+
}
|
|
39
|
+
const firebaseConfig = getFirebaseConfig();
|
|
40
|
+
return initializeApp(firebaseConfig);
|
|
41
|
+
}
|
|
42
|
+
var _app = null;
|
|
43
|
+
var _auth = null;
|
|
44
|
+
var _db = null;
|
|
45
|
+
var _storage = null;
|
|
46
|
+
function getFirebaseApp() {
|
|
47
|
+
if (!_app) {
|
|
48
|
+
_app = initializeFirebase();
|
|
49
|
+
}
|
|
50
|
+
return _app;
|
|
51
|
+
}
|
|
52
|
+
function getFirebaseAuth() {
|
|
53
|
+
if (!_auth) {
|
|
54
|
+
_auth = getAuth(getFirebaseApp());
|
|
55
|
+
}
|
|
56
|
+
return _auth;
|
|
57
|
+
}
|
|
58
|
+
function getFirebaseFirestore() {
|
|
59
|
+
if (!_db) {
|
|
60
|
+
_db = getFirestore(getFirebaseApp());
|
|
61
|
+
}
|
|
62
|
+
return _db;
|
|
63
|
+
}
|
|
64
|
+
function getFirebaseStorage() {
|
|
65
|
+
if (!_storage) {
|
|
66
|
+
_storage = getStorage(getFirebaseApp());
|
|
67
|
+
}
|
|
68
|
+
return _storage;
|
|
69
|
+
}
|
|
70
|
+
typeof window !== "undefined" ? getFirebaseApp() : null;
|
|
71
|
+
typeof window !== "undefined" ? getFirebaseAuth() : null;
|
|
72
|
+
typeof window !== "undefined" ? getFirebaseFirestore() : null;
|
|
73
|
+
typeof window !== "undefined" ? getFirebaseStorage() : null;
|
|
74
|
+
|
|
75
|
+
// src/firebase/auth.ts
|
|
76
|
+
async function signInWithEmail(email, password) {
|
|
77
|
+
const auth2 = getFirebaseAuth();
|
|
78
|
+
return signInWithEmailAndPassword(auth2, email, password);
|
|
79
|
+
}
|
|
80
|
+
async function signUpWithEmail(email, password, displayName) {
|
|
81
|
+
const auth2 = getFirebaseAuth();
|
|
82
|
+
const credential = await createUserWithEmailAndPassword(auth2, email, password);
|
|
83
|
+
if (displayName && credential.user) {
|
|
84
|
+
await updateProfile(credential.user, { displayName });
|
|
85
|
+
}
|
|
86
|
+
return credential;
|
|
87
|
+
}
|
|
88
|
+
async function signOut() {
|
|
89
|
+
const auth2 = getFirebaseAuth();
|
|
90
|
+
return signOut$1(auth2);
|
|
91
|
+
}
|
|
92
|
+
async function resetPassword(email) {
|
|
93
|
+
const auth2 = getFirebaseAuth();
|
|
94
|
+
return sendPasswordResetEmail(auth2, email);
|
|
95
|
+
}
|
|
96
|
+
async function sendVerificationEmail(user) {
|
|
97
|
+
return sendEmailVerification(user);
|
|
98
|
+
}
|
|
99
|
+
async function updateUserProfile(user, profile) {
|
|
100
|
+
return updateProfile(user, profile);
|
|
101
|
+
}
|
|
102
|
+
async function signInWithGoogle() {
|
|
103
|
+
const auth2 = getFirebaseAuth();
|
|
104
|
+
const provider = new GoogleAuthProvider();
|
|
105
|
+
provider.addScope("email");
|
|
106
|
+
provider.addScope("profile");
|
|
107
|
+
return signInWithPopup(auth2, provider);
|
|
108
|
+
}
|
|
109
|
+
function subscribeToAuthState(callback) {
|
|
110
|
+
const auth2 = getFirebaseAuth();
|
|
111
|
+
return onAuthStateChanged(auth2, callback);
|
|
112
|
+
}
|
|
113
|
+
var AuthContext = createContext(void 0);
|
|
114
|
+
function AuthProvider({
|
|
115
|
+
children,
|
|
116
|
+
onAuthStateChange,
|
|
117
|
+
loadingComponent
|
|
118
|
+
}) {
|
|
119
|
+
const [user, setUser] = useState(null);
|
|
120
|
+
const [loading, setLoading] = useState(true);
|
|
121
|
+
const [error, setError] = useState(null);
|
|
122
|
+
useEffect(() => {
|
|
123
|
+
const unsubscribe = subscribeToAuthState((user2) => {
|
|
124
|
+
setUser(user2);
|
|
125
|
+
setLoading(false);
|
|
126
|
+
onAuthStateChange?.(user2);
|
|
127
|
+
});
|
|
128
|
+
return unsubscribe;
|
|
129
|
+
}, [onAuthStateChange]);
|
|
130
|
+
const signIn = useCallback(async (email, password) => {
|
|
131
|
+
setError(null);
|
|
132
|
+
try {
|
|
133
|
+
return await signInWithEmail(email, password);
|
|
134
|
+
} catch (err) {
|
|
135
|
+
const error2 = err;
|
|
136
|
+
setError(error2);
|
|
137
|
+
throw error2;
|
|
138
|
+
}
|
|
139
|
+
}, []);
|
|
140
|
+
const signUp = useCallback(
|
|
141
|
+
async (email, password, displayName) => {
|
|
142
|
+
setError(null);
|
|
143
|
+
try {
|
|
144
|
+
return await signUpWithEmail(email, password, displayName);
|
|
145
|
+
} catch (err) {
|
|
146
|
+
const error2 = err;
|
|
147
|
+
setError(error2);
|
|
148
|
+
throw error2;
|
|
149
|
+
}
|
|
150
|
+
},
|
|
151
|
+
[]
|
|
152
|
+
);
|
|
153
|
+
const signOut2 = useCallback(async () => {
|
|
154
|
+
setError(null);
|
|
155
|
+
try {
|
|
156
|
+
await signOut();
|
|
157
|
+
} catch (err) {
|
|
158
|
+
const error2 = err;
|
|
159
|
+
setError(error2);
|
|
160
|
+
throw error2;
|
|
161
|
+
}
|
|
162
|
+
}, []);
|
|
163
|
+
const signInWithGoogle2 = useCallback(async () => {
|
|
164
|
+
setError(null);
|
|
165
|
+
try {
|
|
166
|
+
return await signInWithGoogle();
|
|
167
|
+
} catch (err) {
|
|
168
|
+
const error2 = err;
|
|
169
|
+
setError(error2);
|
|
170
|
+
throw error2;
|
|
171
|
+
}
|
|
172
|
+
}, []);
|
|
173
|
+
const resetPassword2 = useCallback(async (email) => {
|
|
174
|
+
setError(null);
|
|
175
|
+
try {
|
|
176
|
+
await resetPassword(email);
|
|
177
|
+
} catch (err) {
|
|
178
|
+
const error2 = err;
|
|
179
|
+
setError(error2);
|
|
180
|
+
throw error2;
|
|
181
|
+
}
|
|
182
|
+
}, []);
|
|
183
|
+
const updateProfile2 = useCallback(
|
|
184
|
+
async (profile) => {
|
|
185
|
+
setError(null);
|
|
186
|
+
if (!user) {
|
|
187
|
+
const error2 = new Error("No authenticated user");
|
|
188
|
+
setError(error2);
|
|
189
|
+
throw error2;
|
|
190
|
+
}
|
|
191
|
+
try {
|
|
192
|
+
await updateUserProfile(user, profile);
|
|
193
|
+
} catch (err) {
|
|
194
|
+
const error2 = err;
|
|
195
|
+
setError(error2);
|
|
196
|
+
throw error2;
|
|
197
|
+
}
|
|
198
|
+
},
|
|
199
|
+
[user]
|
|
200
|
+
);
|
|
201
|
+
const sendEmailVerificationFn = useCallback(async () => {
|
|
202
|
+
setError(null);
|
|
203
|
+
if (!user) {
|
|
204
|
+
const error2 = new Error("No authenticated user");
|
|
205
|
+
setError(error2);
|
|
206
|
+
throw error2;
|
|
207
|
+
}
|
|
208
|
+
try {
|
|
209
|
+
await sendVerificationEmail(user);
|
|
210
|
+
} catch (err) {
|
|
211
|
+
const error2 = err;
|
|
212
|
+
setError(error2);
|
|
213
|
+
throw error2;
|
|
214
|
+
}
|
|
215
|
+
}, [user]);
|
|
216
|
+
const clearError = useCallback(() => {
|
|
217
|
+
setError(null);
|
|
218
|
+
}, []);
|
|
219
|
+
const value = useMemo(
|
|
220
|
+
() => ({
|
|
221
|
+
user,
|
|
222
|
+
loading,
|
|
223
|
+
isAuthenticated: !!user,
|
|
224
|
+
error,
|
|
225
|
+
signIn,
|
|
226
|
+
signUp,
|
|
227
|
+
signOut: signOut2,
|
|
228
|
+
signInWithGoogle: signInWithGoogle2,
|
|
229
|
+
resetPassword: resetPassword2,
|
|
230
|
+
updateProfile: updateProfile2,
|
|
231
|
+
sendEmailVerification: sendEmailVerificationFn,
|
|
232
|
+
clearError
|
|
233
|
+
}),
|
|
234
|
+
[
|
|
235
|
+
user,
|
|
236
|
+
loading,
|
|
237
|
+
error,
|
|
238
|
+
signIn,
|
|
239
|
+
signUp,
|
|
240
|
+
signOut2,
|
|
241
|
+
signInWithGoogle2,
|
|
242
|
+
resetPassword2,
|
|
243
|
+
updateProfile2,
|
|
244
|
+
sendEmailVerificationFn,
|
|
245
|
+
clearError
|
|
246
|
+
]
|
|
247
|
+
);
|
|
248
|
+
if (loading && loadingComponent) {
|
|
249
|
+
return /* @__PURE__ */ jsx(Fragment, { children: loadingComponent });
|
|
250
|
+
}
|
|
251
|
+
return /* @__PURE__ */ jsx(AuthContext.Provider, { value, children });
|
|
252
|
+
}
|
|
253
|
+
function useAuthContext() {
|
|
254
|
+
const context = useContext(AuthContext);
|
|
255
|
+
if (context === void 0) {
|
|
256
|
+
throw new Error("useAuthContext must be used within an AuthProvider");
|
|
257
|
+
}
|
|
258
|
+
return context;
|
|
259
|
+
}
|
|
260
|
+
function withAuth(WrappedComponent, options = {}) {
|
|
261
|
+
const { LoadingComponent, UnauthenticatedComponent } = options;
|
|
262
|
+
return function WithAuthComponent(props) {
|
|
263
|
+
const { user, loading, isAuthenticated } = useAuthContext();
|
|
264
|
+
if (loading) {
|
|
265
|
+
return LoadingComponent ? /* @__PURE__ */ jsx(LoadingComponent, {}) : /* @__PURE__ */ jsx("div", { children: "Loading..." });
|
|
266
|
+
}
|
|
267
|
+
if (!isAuthenticated) {
|
|
268
|
+
return UnauthenticatedComponent ? /* @__PURE__ */ jsx(UnauthenticatedComponent, {}) : /* @__PURE__ */ jsx("div", { children: "Please sign in to continue" });
|
|
269
|
+
}
|
|
270
|
+
return /* @__PURE__ */ jsx(WrappedComponent, { ...props });
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
export { AuthProvider, useAuthContext, withAuth };
|
|
275
|
+
//# sourceMappingURL=index.mjs.map
|
|
276
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/firebase/config.ts","../../src/firebase/auth.ts","../../src/context/AuthContext.tsx"],"names":["auth","firebaseSignOut","user","error","signOut","signInWithGoogle","resetPassword","updateProfile"],"mappings":";;;;;;;;AAuBO,SAAS,iBAAA,GAAoC;AAClD,EAAA,MAAM,MAAA,GAAyB;AAAA,IAC7B,MAAA,EAAQ,OAAA,CAAQ,GAAA,CAAI,4BAAA,IAAgC,EAAA;AAAA,IACpD,UAAA,EAAY,OAAA,CAAQ,GAAA,CAAI,gCAAA,IAAoC,EAAA;AAAA,IAC5D,SAAA,EAAW,OAAA,CAAQ,GAAA,CAAI,+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A,gBAAA,EAAiB,CAAA;AAAA,EAC7B;AAEA,EAAA,uBAAO,GAAA,CAAC,WAAA,CAAY,QAAA,EAAZ,EAAqB,OAAe,QAAA,EAAS,CAAA;AACvD;AAwBO,SAAS,cAAA,GAAmC;AACjD,EAAA,MAAM,OAAA,GAAU,WAAW,WAAW,CAAA;AAEtC,EAAA,IAAI,YAAY,MAAA,EAAW;AACzB,IAAA,MAAM,IAAI,MAAM,oDAAoD,CAAA;AAAA,EACtE;AAEA,EAAA,OAAO,OAAA;AACT;AAMO,SAAS,QAAA,CACd,gBAAA,EACA,OAAA,GAGI,EAAC,EACL;AACA,EAAA,MAAM,EAAE,gBAAA,EAAkB,wBAAA,EAAyB,GAAI,OAAA;AAEvD,EAAA,OAAO,SAAS,kBAAkB,KAAA,EAAU;AAC1C,IAAA,MAAM,EAAE,IAAA,EAAM,OAAA,EAAS,eAAA,KAAoB,cAAA,EAAe;AAE1D,IAAA,IAAI,OAAA,EAAS;AACX,MAAA,OAAO,mCAAmB,GAAA,CAAC,gBAAA,EAAA,EAAiB,CAAA,mBAAK,GAAA,CAAC,SAAI,QAAA,EAAA,YAAA,EAAU,CAAA;AAAA,IAClE;AAEA,IAAA,IAAI,CAAC,eAAA,EAAiB;AACpB,MAAA,OAAO,2CACL,GAAA,CAAC,wBAAA,EAAA,EAAyB,CAAA,mBAE1B,GAAA,CAAC,SAAI,QAAA,EAAA,4BAAA,EAA0B,CAAA;AAAA,IAEnC;AAEA,IAAA,uBAAO,GAAA,CAAC,gBAAA,EAAA,EAAkB,GAAG,KAAA,EAAO,CAAA;AAAA,EACtC,CAAA;AACF","file":"index.mjs","sourcesContent":["import { initializeApp, getApps, getApp, FirebaseApp } from 'firebase/app';\nimport { getAuth, Auth } from 'firebase/auth';\nimport { getFirestore, Firestore } from 'firebase/firestore';\nimport { getStorage, FirebaseStorage } from 'firebase/storage';\n\n/**\n * Firebase configuration interface\n * All values should be provided via environment variables\n */\nexport interface FirebaseConfig {\n apiKey: string;\n authDomain: string;\n projectId: string;\n storageBucket: string;\n messagingSenderId: string;\n appId: string;\n measurementId?: string;\n}\n\n/**\n * Get Firebase configuration from environment variables\n * Works with Next.js NEXT_PUBLIC_ prefix\n */\nexport function getFirebaseConfig(): FirebaseConfig {\n const config: FirebaseConfig = {\n apiKey: process.env.NEXT_PUBLIC_FIREBASE_API_KEY || '',\n authDomain: process.env.NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN || '',\n projectId: process.env.NEXT_PUBLIC_FIREBASE_PROJECT_ID || '',\n storageBucket: process.env.NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET || '',\n messagingSenderId: process.env.NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID || '',\n appId: process.env.NEXT_PUBLIC_FIREBASE_APP_ID || '',\n measurementId: process.env.NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID,\n };\n\n // Validate required fields\n const requiredFields: (keyof FirebaseConfig)[] = [\n 'apiKey',\n 'authDomain',\n 'projectId',\n 'storageBucket',\n 'messagingSenderId',\n 'appId',\n ];\n\n const missingFields = requiredFields.filter((field) => !config[field]);\n\n if (missingFields.length > 0) {\n console.warn(\n `[mw-core] Missing Firebase config fields: ${missingFields.join(', ')}. ` +\n `Make sure to set NEXT_PUBLIC_FIREBASE_* environment variables.`\n );\n }\n\n return config;\n}\n\n/**\n * Initialize Firebase app (singleton pattern)\n * Safe to call multiple times - returns existing instance if already initialized\n */\nexport function initializeFirebase(config?: FirebaseConfig): FirebaseApp {\n if (getApps().length > 0) {\n return getApp();\n }\n\n const firebaseConfig = config || getFirebaseConfig();\n return initializeApp(firebaseConfig);\n}\n\n// Lazy initialization singletons\nlet _app: FirebaseApp | null = null;\nlet _auth: Auth | null = null;\nlet _db: Firestore | null = null;\nlet _storage: FirebaseStorage | null = null;\n\n/**\n * Get the Firebase app instance\n */\nexport function getFirebaseApp(): FirebaseApp {\n if (!_app) {\n _app = initializeFirebase();\n }\n return _app;\n}\n\n/**\n * Get the Firebase Auth instance\n */\nexport function getFirebaseAuth(): Auth {\n if (!_auth) {\n _auth = getAuth(getFirebaseApp());\n }\n return _auth;\n}\n\n/**\n * Get the Firestore database instance\n */\nexport function getFirebaseFirestore(): Firestore {\n if (!_db) {\n _db = getFirestore(getFirebaseApp());\n }\n return _db;\n}\n\n/**\n * Get the Firebase Storage instance\n */\nexport function getFirebaseStorage(): FirebaseStorage {\n if (!_storage) {\n _storage = getStorage(getFirebaseApp());\n }\n return _storage;\n}\n\n// Convenience exports for direct access\nexport const app = typeof window !== 'undefined' ? getFirebaseApp() : null;\nexport const auth = typeof window !== 'undefined' ? getFirebaseAuth() : null;\nexport const db = typeof window !== 'undefined' ? getFirebaseFirestore() : null;\nexport const storage = typeof window !== 'undefined' ? getFirebaseStorage() : null;\n\n","import {\n signInWithEmailAndPassword,\n createUserWithEmailAndPassword,\n signOut as firebaseSignOut,\n sendPasswordResetEmail,\n sendEmailVerification,\n updateProfile,\n GoogleAuthProvider,\n signInWithPopup,\n signInWithRedirect,\n getRedirectResult,\n onAuthStateChanged,\n User,\n UserCredential,\n Auth,\n} from 'firebase/auth';\nimport { getFirebaseAuth } from './config';\n\n/**\n * Sign in with email and password\n */\nexport async function signInWithEmail(\n email: string,\n password: string\n): Promise<UserCredential> {\n const auth = getFirebaseAuth();\n return signInWithEmailAndPassword(auth, email, password);\n}\n\n/**\n * Create a new account with email and password\n */\nexport async function signUpWithEmail(\n email: string,\n password: string,\n displayName?: string\n): Promise<UserCredential> {\n const auth = getFirebaseAuth();\n const credential = await createUserWithEmailAndPassword(auth, email, password);\n \n if (displayName && credential.user) {\n await updateProfile(credential.user, { displayName });\n }\n \n return credential;\n}\n\n/**\n * Sign out the current user\n */\nexport async function signOut(): Promise<void> {\n const auth = getFirebaseAuth();\n return firebaseSignOut(auth);\n}\n\n/**\n * Send a password reset email\n */\nexport async function resetPassword(email: string): Promise<void> {\n const auth = getFirebaseAuth();\n return sendPasswordResetEmail(auth, email);\n}\n\n/**\n * Send email verification to the current user\n */\nexport async function sendVerificationEmail(user: User): Promise<void> {\n return sendEmailVerification(user);\n}\n\n/**\n * Update the current user's profile\n */\nexport async function updateUserProfile(\n user: User,\n profile: { displayName?: string; photoURL?: string }\n): Promise<void> {\n return updateProfile(user, profile);\n}\n\n/**\n * Sign in with Google using popup\n */\nexport async function signInWithGoogle(): Promise<UserCredential> {\n const auth = getFirebaseAuth();\n const provider = new GoogleAuthProvider();\n provider.addScope('email');\n provider.addScope('profile');\n return signInWithPopup(auth, provider);\n}\n\n/**\n * Sign in with Google using redirect (better for mobile)\n */\nexport async function signInWithGoogleRedirect(): Promise<void> {\n const auth = getFirebaseAuth();\n const provider = new GoogleAuthProvider();\n provider.addScope('email');\n provider.addScope('profile');\n return signInWithRedirect(auth, provider);\n}\n\n/**\n * Get the result of a redirect sign-in\n */\nexport async function getGoogleRedirectResult(): Promise<UserCredential | null> {\n const auth = getFirebaseAuth();\n return getRedirectResult(auth);\n}\n\n/**\n * Subscribe to auth state changes\n */\nexport function subscribeToAuthState(\n callback: (user: User | null) => void\n): () => void {\n const auth = getFirebaseAuth();\n return onAuthStateChanged(auth, callback);\n}\n\n/**\n * Get the current user (may be null if not authenticated)\n */\nexport function getCurrentUser(): User | null {\n const auth = getFirebaseAuth();\n return auth.currentUser;\n}\n\n/**\n * Wait for the auth state to be determined\n * Useful for SSR/initial load\n */\nexport function waitForAuthState(): Promise<User | null> {\n return new Promise((resolve) => {\n const auth = getFirebaseAuth();\n const unsubscribe = onAuthStateChanged(auth, (user) => {\n unsubscribe();\n resolve(user);\n });\n });\n}\n\n// Re-export useful types\nexport type { User, UserCredential, Auth };\n\n","'use client';\n\nimport React, {\n createContext,\n useContext,\n useState,\n useEffect,\n useCallback,\n useMemo,\n ReactNode,\n} from 'react';\nimport { User, UserCredential } from 'firebase/auth';\nimport {\n subscribeToAuthState,\n signInWithEmail,\n signUpWithEmail,\n signOut as firebaseSignOut,\n signInWithGoogle as firebaseSignInWithGoogle,\n resetPassword as firebaseResetPassword,\n updateUserProfile,\n sendVerificationEmail,\n} from '../firebase/auth';\n\nexport interface AuthContextValue {\n /** The current authenticated user, or null if not authenticated */\n user: User | null;\n /** Whether the auth state is still loading */\n loading: boolean;\n /** Whether the user is authenticated */\n isAuthenticated: boolean;\n /** Any auth error that occurred */\n error: Error | null;\n /** Sign in with email and password */\n signIn: (email: string, password: string) => Promise<UserCredential>;\n /** Create a new account with email and password */\n signUp: (email: string, password: string, displayName?: string) => Promise<UserCredential>;\n /** Sign out the current user */\n signOut: () => Promise<void>;\n /** Sign in with Google */\n signInWithGoogle: () => Promise<UserCredential>;\n /** Send a password reset email */\n resetPassword: (email: string) => Promise<void>;\n /** Update the user's profile */\n updateProfile: (profile: { displayName?: string; photoURL?: string }) => Promise<void>;\n /** Send email verification */\n sendEmailVerification: () => Promise<void>;\n /** Clear any auth errors */\n clearError: () => void;\n}\n\nconst AuthContext = createContext<AuthContextValue | undefined>(undefined);\n\nexport interface AuthProviderProps {\n children: ReactNode;\n /** Optional: Called when auth state changes */\n onAuthStateChange?: (user: User | null) => void;\n /** Optional: Loading component to show while auth state is loading */\n loadingComponent?: ReactNode;\n}\n\n/**\n * Auth Provider component that wraps your app and provides auth context\n * \n * @example\n * ```tsx\n * // app/layout.tsx\n * import { AuthProvider } from '@marcwelti/mw-core';\n * \n * export default function RootLayout({ children }) {\n * return (\n * <html>\n * <body>\n * <AuthProvider>\n * {children}\n * </AuthProvider>\n * </body>\n * </html>\n * );\n * }\n * ```\n */\nexport function AuthProvider({\n children,\n onAuthStateChange,\n loadingComponent,\n}: AuthProviderProps) {\n const [user, setUser] = useState<User | null>(null);\n const [loading, setLoading] = useState(true);\n const [error, setError] = useState<Error | null>(null);\n\n useEffect(() => {\n const unsubscribe = subscribeToAuthState((user) => {\n setUser(user);\n setLoading(false);\n onAuthStateChange?.(user);\n });\n\n return unsubscribe;\n }, [onAuthStateChange]);\n\n const signIn = useCallback(async (email: string, password: string) => {\n setError(null);\n try {\n return await signInWithEmail(email, password);\n } catch (err) {\n const error = err as Error;\n setError(error);\n throw error;\n }\n }, []);\n\n const signUp = useCallback(\n async (email: string, password: string, displayName?: string) => {\n setError(null);\n try {\n return await signUpWithEmail(email, password, displayName);\n } catch (err) {\n const error = err as Error;\n setError(error);\n throw error;\n }\n },\n []\n );\n\n const signOut = useCallback(async () => {\n setError(null);\n try {\n await firebaseSignOut();\n } catch (err) {\n const error = err as Error;\n setError(error);\n throw error;\n }\n }, []);\n\n const signInWithGoogle = useCallback(async () => {\n setError(null);\n try {\n return await firebaseSignInWithGoogle();\n } catch (err) {\n const error = err as Error;\n setError(error);\n throw error;\n }\n }, []);\n\n const resetPassword = useCallback(async (email: string) => {\n setError(null);\n try {\n await firebaseResetPassword(email);\n } catch (err) {\n const error = err as Error;\n setError(error);\n throw error;\n }\n }, []);\n\n const updateProfile = useCallback(\n async (profile: { displayName?: string; photoURL?: string }) => {\n setError(null);\n if (!user) {\n const error = new Error('No authenticated user');\n setError(error);\n throw error;\n }\n try {\n await updateUserProfile(user, profile);\n } catch (err) {\n const error = err as Error;\n setError(error);\n throw error;\n }\n },\n [user]\n );\n\n const sendEmailVerificationFn = useCallback(async () => {\n setError(null);\n if (!user) {\n const error = new Error('No authenticated user');\n setError(error);\n throw error;\n }\n try {\n await sendVerificationEmail(user);\n } catch (err) {\n const error = err as Error;\n setError(error);\n throw error;\n }\n }, [user]);\n\n const clearError = useCallback(() => {\n setError(null);\n }, []);\n\n const value = useMemo<AuthContextValue>(\n () => ({\n user,\n loading,\n isAuthenticated: !!user,\n error,\n signIn,\n signUp,\n signOut,\n signInWithGoogle,\n resetPassword,\n updateProfile,\n sendEmailVerification: sendEmailVerificationFn,\n clearError,\n }),\n [\n user,\n loading,\n error,\n signIn,\n signUp,\n signOut,\n signInWithGoogle,\n resetPassword,\n updateProfile,\n sendEmailVerificationFn,\n clearError,\n ]\n );\n\n // Show loading component while determining auth state\n if (loading && loadingComponent) {\n return <>{loadingComponent}</>;\n }\n\n return <AuthContext.Provider value={value}>{children}</AuthContext.Provider>;\n}\n\n/**\n * Hook to access auth context\n * Must be used within an AuthProvider\n * \n * @example\n * ```tsx\n * function MyComponent() {\n * const { user, signOut, isAuthenticated } = useAuthContext();\n * \n * if (!isAuthenticated) {\n * return <LoginForm />;\n * }\n * \n * return (\n * <div>\n * <p>Welcome, {user?.displayName}</p>\n * <button onClick={signOut}>Sign Out</button>\n * </div>\n * );\n * }\n * ```\n */\nexport function useAuthContext(): AuthContextValue {\n const context = useContext(AuthContext);\n \n if (context === undefined) {\n throw new Error('useAuthContext must be used within an AuthProvider');\n }\n \n return context;\n}\n\n/**\n * HOC for protecting routes that require authentication\n * Redirects to login or shows loading state\n */\nexport function withAuth<P extends object>(\n WrappedComponent: React.ComponentType<P>,\n options: {\n LoadingComponent?: React.ComponentType;\n UnauthenticatedComponent?: React.ComponentType;\n } = {}\n) {\n const { LoadingComponent, UnauthenticatedComponent } = options;\n\n return function WithAuthComponent(props: P) {\n const { user, loading, isAuthenticated } = useAuthContext();\n\n if (loading) {\n return LoadingComponent ? <LoadingComponent /> : <div>Loading...</div>;\n }\n\n if (!isAuthenticated) {\n return UnauthenticatedComponent ? (\n <UnauthenticatedComponent />\n ) : (\n <div>Please sign in to continue</div>\n );\n }\n\n return <WrappedComponent {...props} />;\n };\n}\n\n"]}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { FirebaseApp } from 'firebase/app';
|
|
2
|
+
import { Auth, User, UserCredential } from 'firebase/auth';
|
|
3
|
+
export { Auth, User, UserCredential } from 'firebase/auth';
|
|
4
|
+
import { Firestore, DocumentData, QueryConstraint, CollectionReference, DocumentReference, Unsubscribe } from 'firebase/firestore';
|
|
5
|
+
export { CollectionReference, DocumentData, DocumentReference, DocumentSnapshot, FieldValue, OrderByDirection, QueryConstraint, QuerySnapshot, Timestamp, Unsubscribe, WhereFilterOp, limit, orderBy, query, serverTimestamp, startAfter, where } from 'firebase/firestore';
|
|
6
|
+
import { FirebaseStorage } from 'firebase/storage';
|
|
7
|
+
export { FullMetadata, ListResult, StorageReference, UploadMetadata, UploadTask } from 'firebase/storage';
|
|
8
|
+
export { d as deleteFile, g as generateFilePath, a as getFileMetadata, b as getFileURL, c as getStorageRef, l as listFiles, u as updateFileMetadata, e as uploadFile, f as uploadFileWithProgress } from '../storage-BU_rfYCi.mjs';
|
|
9
|
+
import { Analytics } from 'firebase/analytics';
|
|
10
|
+
export { Analytics } from 'firebase/analytics';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Firebase configuration interface
|
|
14
|
+
* All values should be provided via environment variables
|
|
15
|
+
*/
|
|
16
|
+
interface FirebaseConfig {
|
|
17
|
+
apiKey: string;
|
|
18
|
+
authDomain: string;
|
|
19
|
+
projectId: string;
|
|
20
|
+
storageBucket: string;
|
|
21
|
+
messagingSenderId: string;
|
|
22
|
+
appId: string;
|
|
23
|
+
measurementId?: string;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Get Firebase configuration from environment variables
|
|
27
|
+
* Works with Next.js NEXT_PUBLIC_ prefix
|
|
28
|
+
*/
|
|
29
|
+
declare function getFirebaseConfig(): FirebaseConfig;
|
|
30
|
+
/**
|
|
31
|
+
* Initialize Firebase app (singleton pattern)
|
|
32
|
+
* Safe to call multiple times - returns existing instance if already initialized
|
|
33
|
+
*/
|
|
34
|
+
declare function initializeFirebase(config?: FirebaseConfig): FirebaseApp;
|
|
35
|
+
/**
|
|
36
|
+
* Get the Firebase app instance
|
|
37
|
+
*/
|
|
38
|
+
declare function getFirebaseApp(): FirebaseApp;
|
|
39
|
+
/**
|
|
40
|
+
* Get the Firebase Auth instance
|
|
41
|
+
*/
|
|
42
|
+
declare function getFirebaseAuth(): Auth;
|
|
43
|
+
/**
|
|
44
|
+
* Get the Firestore database instance
|
|
45
|
+
*/
|
|
46
|
+
declare function getFirebaseFirestore(): Firestore;
|
|
47
|
+
/**
|
|
48
|
+
* Get the Firebase Storage instance
|
|
49
|
+
*/
|
|
50
|
+
declare function getFirebaseStorage(): FirebaseStorage;
|
|
51
|
+
declare const app: FirebaseApp | null;
|
|
52
|
+
declare const auth: Auth | null;
|
|
53
|
+
declare const db: Firestore | null;
|
|
54
|
+
declare const storage: FirebaseStorage | null;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Sign in with email and password
|
|
58
|
+
*/
|
|
59
|
+
declare function signInWithEmail(email: string, password: string): Promise<UserCredential>;
|
|
60
|
+
/**
|
|
61
|
+
* Create a new account with email and password
|
|
62
|
+
*/
|
|
63
|
+
declare function signUpWithEmail(email: string, password: string, displayName?: string): Promise<UserCredential>;
|
|
64
|
+
/**
|
|
65
|
+
* Sign out the current user
|
|
66
|
+
*/
|
|
67
|
+
declare function signOut(): Promise<void>;
|
|
68
|
+
/**
|
|
69
|
+
* Send a password reset email
|
|
70
|
+
*/
|
|
71
|
+
declare function resetPassword(email: string): Promise<void>;
|
|
72
|
+
/**
|
|
73
|
+
* Send email verification to the current user
|
|
74
|
+
*/
|
|
75
|
+
declare function sendVerificationEmail(user: User): Promise<void>;
|
|
76
|
+
/**
|
|
77
|
+
* Update the current user's profile
|
|
78
|
+
*/
|
|
79
|
+
declare function updateUserProfile(user: User, profile: {
|
|
80
|
+
displayName?: string;
|
|
81
|
+
photoURL?: string;
|
|
82
|
+
}): Promise<void>;
|
|
83
|
+
/**
|
|
84
|
+
* Sign in with Google using popup
|
|
85
|
+
*/
|
|
86
|
+
declare function signInWithGoogle(): Promise<UserCredential>;
|
|
87
|
+
/**
|
|
88
|
+
* Sign in with Google using redirect (better for mobile)
|
|
89
|
+
*/
|
|
90
|
+
declare function signInWithGoogleRedirect(): Promise<void>;
|
|
91
|
+
/**
|
|
92
|
+
* Get the result of a redirect sign-in
|
|
93
|
+
*/
|
|
94
|
+
declare function getGoogleRedirectResult(): Promise<UserCredential | null>;
|
|
95
|
+
/**
|
|
96
|
+
* Subscribe to auth state changes
|
|
97
|
+
*/
|
|
98
|
+
declare function subscribeToAuthState(callback: (user: User | null) => void): () => void;
|
|
99
|
+
/**
|
|
100
|
+
* Get the current user (may be null if not authenticated)
|
|
101
|
+
*/
|
|
102
|
+
declare function getCurrentUser(): User | null;
|
|
103
|
+
/**
|
|
104
|
+
* Wait for the auth state to be determined
|
|
105
|
+
* Useful for SSR/initial load
|
|
106
|
+
*/
|
|
107
|
+
declare function waitForAuthState(): Promise<User | null>;
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Get a document reference
|
|
111
|
+
*/
|
|
112
|
+
declare function getDocRef<T = DocumentData>(collectionPath: string, documentId: string): DocumentReference<T>;
|
|
113
|
+
/**
|
|
114
|
+
* Get a collection reference
|
|
115
|
+
*/
|
|
116
|
+
declare function getCollectionRef<T = DocumentData>(collectionPath: string): CollectionReference<T>;
|
|
117
|
+
/**
|
|
118
|
+
* Get a single document by ID
|
|
119
|
+
*/
|
|
120
|
+
declare function getDocument<T = DocumentData>(collectionPath: string, documentId: string): Promise<T | null>;
|
|
121
|
+
/**
|
|
122
|
+
* Get all documents in a collection
|
|
123
|
+
*/
|
|
124
|
+
declare function getCollection<T = DocumentData>(collectionPath: string, constraints?: QueryConstraint[]): Promise<T[]>;
|
|
125
|
+
/**
|
|
126
|
+
* Add a new document with auto-generated ID
|
|
127
|
+
*/
|
|
128
|
+
declare function addDocument<T = DocumentData>(collectionPath: string, data: Omit<T, 'id'>): Promise<string>;
|
|
129
|
+
/**
|
|
130
|
+
* Set/create a document with a specific ID
|
|
131
|
+
*/
|
|
132
|
+
declare function setDocument<T = DocumentData>(collectionPath: string, documentId: string, data: Omit<T, 'id'>, merge?: boolean): Promise<void>;
|
|
133
|
+
/**
|
|
134
|
+
* Update specific fields in a document
|
|
135
|
+
*/
|
|
136
|
+
declare function updateDocument<T = DocumentData>(collectionPath: string, documentId: string, data: Partial<T>): Promise<void>;
|
|
137
|
+
/**
|
|
138
|
+
* Delete a document
|
|
139
|
+
*/
|
|
140
|
+
declare function deleteDocument(collectionPath: string, documentId: string): Promise<void>;
|
|
141
|
+
/**
|
|
142
|
+
* Subscribe to a single document
|
|
143
|
+
*/
|
|
144
|
+
declare function subscribeToDocument<T = DocumentData>(collectionPath: string, documentId: string, callback: (data: T | null) => void): Unsubscribe;
|
|
145
|
+
/**
|
|
146
|
+
* Subscribe to a collection
|
|
147
|
+
*/
|
|
148
|
+
declare function subscribeToCollection<T = DocumentData>(collectionPath: string, callback: (data: T[]) => void, constraints?: QueryConstraint[]): Unsubscribe;
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Get the Firebase Analytics instance
|
|
152
|
+
* Only works in browser environment
|
|
153
|
+
*/
|
|
154
|
+
declare function getFirebaseAnalytics(): Promise<Analytics | null>;
|
|
155
|
+
/**
|
|
156
|
+
* Log a custom event to Firebase Analytics
|
|
157
|
+
*/
|
|
158
|
+
declare function trackEvent(eventName: string, eventParams?: Record<string, unknown>): Promise<void>;
|
|
159
|
+
/**
|
|
160
|
+
* Track a page view
|
|
161
|
+
*/
|
|
162
|
+
declare function trackPageView(pagePath: string, pageTitle?: string): Promise<void>;
|
|
163
|
+
/**
|
|
164
|
+
* Track a user action
|
|
165
|
+
*/
|
|
166
|
+
declare function trackUserAction(action: string, category: string, label?: string, value?: number): Promise<void>;
|
|
167
|
+
/**
|
|
168
|
+
* Track sign up event
|
|
169
|
+
*/
|
|
170
|
+
declare function trackSignUp(method: string): Promise<void>;
|
|
171
|
+
/**
|
|
172
|
+
* Track login event
|
|
173
|
+
*/
|
|
174
|
+
declare function trackLogin(method: string): Promise<void>;
|
|
175
|
+
|
|
176
|
+
export { type FirebaseConfig, addDocument, app, auth, db, deleteDocument, getCollection, getCollectionRef, getCurrentUser, getDocRef, getDocument, getFirebaseAnalytics, getFirebaseApp, getFirebaseAuth, getFirebaseConfig, getFirebaseFirestore, getFirebaseStorage, getGoogleRedirectResult, initializeFirebase, resetPassword, sendVerificationEmail, setDocument, signInWithEmail, signInWithGoogle, signInWithGoogleRedirect, signOut, signUpWithEmail, storage, subscribeToAuthState, subscribeToCollection, subscribeToDocument, trackEvent, trackLogin, trackPageView, trackSignUp, trackUserAction, updateDocument, updateUserProfile, waitForAuthState };
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { FirebaseApp } from 'firebase/app';
|
|
2
|
+
import { Auth, User, UserCredential } from 'firebase/auth';
|
|
3
|
+
export { Auth, User, UserCredential } from 'firebase/auth';
|
|
4
|
+
import { Firestore, DocumentData, QueryConstraint, CollectionReference, DocumentReference, Unsubscribe } from 'firebase/firestore';
|
|
5
|
+
export { CollectionReference, DocumentData, DocumentReference, DocumentSnapshot, FieldValue, OrderByDirection, QueryConstraint, QuerySnapshot, Timestamp, Unsubscribe, WhereFilterOp, limit, orderBy, query, serverTimestamp, startAfter, where } from 'firebase/firestore';
|
|
6
|
+
import { FirebaseStorage } from 'firebase/storage';
|
|
7
|
+
export { FullMetadata, ListResult, StorageReference, UploadMetadata, UploadTask } from 'firebase/storage';
|
|
8
|
+
export { d as deleteFile, g as generateFilePath, a as getFileMetadata, b as getFileURL, c as getStorageRef, l as listFiles, u as updateFileMetadata, e as uploadFile, f as uploadFileWithProgress } from '../storage-BU_rfYCi.js';
|
|
9
|
+
import { Analytics } from 'firebase/analytics';
|
|
10
|
+
export { Analytics } from 'firebase/analytics';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Firebase configuration interface
|
|
14
|
+
* All values should be provided via environment variables
|
|
15
|
+
*/
|
|
16
|
+
interface FirebaseConfig {
|
|
17
|
+
apiKey: string;
|
|
18
|
+
authDomain: string;
|
|
19
|
+
projectId: string;
|
|
20
|
+
storageBucket: string;
|
|
21
|
+
messagingSenderId: string;
|
|
22
|
+
appId: string;
|
|
23
|
+
measurementId?: string;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Get Firebase configuration from environment variables
|
|
27
|
+
* Works with Next.js NEXT_PUBLIC_ prefix
|
|
28
|
+
*/
|
|
29
|
+
declare function getFirebaseConfig(): FirebaseConfig;
|
|
30
|
+
/**
|
|
31
|
+
* Initialize Firebase app (singleton pattern)
|
|
32
|
+
* Safe to call multiple times - returns existing instance if already initialized
|
|
33
|
+
*/
|
|
34
|
+
declare function initializeFirebase(config?: FirebaseConfig): FirebaseApp;
|
|
35
|
+
/**
|
|
36
|
+
* Get the Firebase app instance
|
|
37
|
+
*/
|
|
38
|
+
declare function getFirebaseApp(): FirebaseApp;
|
|
39
|
+
/**
|
|
40
|
+
* Get the Firebase Auth instance
|
|
41
|
+
*/
|
|
42
|
+
declare function getFirebaseAuth(): Auth;
|
|
43
|
+
/**
|
|
44
|
+
* Get the Firestore database instance
|
|
45
|
+
*/
|
|
46
|
+
declare function getFirebaseFirestore(): Firestore;
|
|
47
|
+
/**
|
|
48
|
+
* Get the Firebase Storage instance
|
|
49
|
+
*/
|
|
50
|
+
declare function getFirebaseStorage(): FirebaseStorage;
|
|
51
|
+
declare const app: FirebaseApp | null;
|
|
52
|
+
declare const auth: Auth | null;
|
|
53
|
+
declare const db: Firestore | null;
|
|
54
|
+
declare const storage: FirebaseStorage | null;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Sign in with email and password
|
|
58
|
+
*/
|
|
59
|
+
declare function signInWithEmail(email: string, password: string): Promise<UserCredential>;
|
|
60
|
+
/**
|
|
61
|
+
* Create a new account with email and password
|
|
62
|
+
*/
|
|
63
|
+
declare function signUpWithEmail(email: string, password: string, displayName?: string): Promise<UserCredential>;
|
|
64
|
+
/**
|
|
65
|
+
* Sign out the current user
|
|
66
|
+
*/
|
|
67
|
+
declare function signOut(): Promise<void>;
|
|
68
|
+
/**
|
|
69
|
+
* Send a password reset email
|
|
70
|
+
*/
|
|
71
|
+
declare function resetPassword(email: string): Promise<void>;
|
|
72
|
+
/**
|
|
73
|
+
* Send email verification to the current user
|
|
74
|
+
*/
|
|
75
|
+
declare function sendVerificationEmail(user: User): Promise<void>;
|
|
76
|
+
/**
|
|
77
|
+
* Update the current user's profile
|
|
78
|
+
*/
|
|
79
|
+
declare function updateUserProfile(user: User, profile: {
|
|
80
|
+
displayName?: string;
|
|
81
|
+
photoURL?: string;
|
|
82
|
+
}): Promise<void>;
|
|
83
|
+
/**
|
|
84
|
+
* Sign in with Google using popup
|
|
85
|
+
*/
|
|
86
|
+
declare function signInWithGoogle(): Promise<UserCredential>;
|
|
87
|
+
/**
|
|
88
|
+
* Sign in with Google using redirect (better for mobile)
|
|
89
|
+
*/
|
|
90
|
+
declare function signInWithGoogleRedirect(): Promise<void>;
|
|
91
|
+
/**
|
|
92
|
+
* Get the result of a redirect sign-in
|
|
93
|
+
*/
|
|
94
|
+
declare function getGoogleRedirectResult(): Promise<UserCredential | null>;
|
|
95
|
+
/**
|
|
96
|
+
* Subscribe to auth state changes
|
|
97
|
+
*/
|
|
98
|
+
declare function subscribeToAuthState(callback: (user: User | null) => void): () => void;
|
|
99
|
+
/**
|
|
100
|
+
* Get the current user (may be null if not authenticated)
|
|
101
|
+
*/
|
|
102
|
+
declare function getCurrentUser(): User | null;
|
|
103
|
+
/**
|
|
104
|
+
* Wait for the auth state to be determined
|
|
105
|
+
* Useful for SSR/initial load
|
|
106
|
+
*/
|
|
107
|
+
declare function waitForAuthState(): Promise<User | null>;
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Get a document reference
|
|
111
|
+
*/
|
|
112
|
+
declare function getDocRef<T = DocumentData>(collectionPath: string, documentId: string): DocumentReference<T>;
|
|
113
|
+
/**
|
|
114
|
+
* Get a collection reference
|
|
115
|
+
*/
|
|
116
|
+
declare function getCollectionRef<T = DocumentData>(collectionPath: string): CollectionReference<T>;
|
|
117
|
+
/**
|
|
118
|
+
* Get a single document by ID
|
|
119
|
+
*/
|
|
120
|
+
declare function getDocument<T = DocumentData>(collectionPath: string, documentId: string): Promise<T | null>;
|
|
121
|
+
/**
|
|
122
|
+
* Get all documents in a collection
|
|
123
|
+
*/
|
|
124
|
+
declare function getCollection<T = DocumentData>(collectionPath: string, constraints?: QueryConstraint[]): Promise<T[]>;
|
|
125
|
+
/**
|
|
126
|
+
* Add a new document with auto-generated ID
|
|
127
|
+
*/
|
|
128
|
+
declare function addDocument<T = DocumentData>(collectionPath: string, data: Omit<T, 'id'>): Promise<string>;
|
|
129
|
+
/**
|
|
130
|
+
* Set/create a document with a specific ID
|
|
131
|
+
*/
|
|
132
|
+
declare function setDocument<T = DocumentData>(collectionPath: string, documentId: string, data: Omit<T, 'id'>, merge?: boolean): Promise<void>;
|
|
133
|
+
/**
|
|
134
|
+
* Update specific fields in a document
|
|
135
|
+
*/
|
|
136
|
+
declare function updateDocument<T = DocumentData>(collectionPath: string, documentId: string, data: Partial<T>): Promise<void>;
|
|
137
|
+
/**
|
|
138
|
+
* Delete a document
|
|
139
|
+
*/
|
|
140
|
+
declare function deleteDocument(collectionPath: string, documentId: string): Promise<void>;
|
|
141
|
+
/**
|
|
142
|
+
* Subscribe to a single document
|
|
143
|
+
*/
|
|
144
|
+
declare function subscribeToDocument<T = DocumentData>(collectionPath: string, documentId: string, callback: (data: T | null) => void): Unsubscribe;
|
|
145
|
+
/**
|
|
146
|
+
* Subscribe to a collection
|
|
147
|
+
*/
|
|
148
|
+
declare function subscribeToCollection<T = DocumentData>(collectionPath: string, callback: (data: T[]) => void, constraints?: QueryConstraint[]): Unsubscribe;
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Get the Firebase Analytics instance
|
|
152
|
+
* Only works in browser environment
|
|
153
|
+
*/
|
|
154
|
+
declare function getFirebaseAnalytics(): Promise<Analytics | null>;
|
|
155
|
+
/**
|
|
156
|
+
* Log a custom event to Firebase Analytics
|
|
157
|
+
*/
|
|
158
|
+
declare function trackEvent(eventName: string, eventParams?: Record<string, unknown>): Promise<void>;
|
|
159
|
+
/**
|
|
160
|
+
* Track a page view
|
|
161
|
+
*/
|
|
162
|
+
declare function trackPageView(pagePath: string, pageTitle?: string): Promise<void>;
|
|
163
|
+
/**
|
|
164
|
+
* Track a user action
|
|
165
|
+
*/
|
|
166
|
+
declare function trackUserAction(action: string, category: string, label?: string, value?: number): Promise<void>;
|
|
167
|
+
/**
|
|
168
|
+
* Track sign up event
|
|
169
|
+
*/
|
|
170
|
+
declare function trackSignUp(method: string): Promise<void>;
|
|
171
|
+
/**
|
|
172
|
+
* Track login event
|
|
173
|
+
*/
|
|
174
|
+
declare function trackLogin(method: string): Promise<void>;
|
|
175
|
+
|
|
176
|
+
export { type FirebaseConfig, addDocument, app, auth, db, deleteDocument, getCollection, getCollectionRef, getCurrentUser, getDocRef, getDocument, getFirebaseAnalytics, getFirebaseApp, getFirebaseAuth, getFirebaseConfig, getFirebaseFirestore, getFirebaseStorage, getGoogleRedirectResult, initializeFirebase, resetPassword, sendVerificationEmail, setDocument, signInWithEmail, signInWithGoogle, signInWithGoogleRedirect, signOut, signUpWithEmail, storage, subscribeToAuthState, subscribeToCollection, subscribeToDocument, trackEvent, trackLogin, trackPageView, trackSignUp, trackUserAction, updateDocument, updateUserProfile, waitForAuthState };
|