@libreapps/auth 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (127) hide show
  1. package/.turbo/turbo-build.log +4 -0
  2. package/CHANGELOG.md +20 -0
  3. package/LICENSE.md +21 -0
  4. package/README.md +61 -0
  5. package/components/auth-widget.tsx +110 -0
  6. package/components/email-password-form.tsx +96 -0
  7. package/components/index.ts +4 -0
  8. package/components/login-panel.tsx +207 -0
  9. package/components/signup-panel.tsx +213 -0
  10. package/dist/components/auth-widget.d.ts +13 -0
  11. package/dist/components/auth-widget.js +33 -0
  12. package/dist/components/auth-widget.js.map +1 -0
  13. package/dist/components/email-password-form.d.ts +8 -0
  14. package/dist/components/email-password-form.js +25 -0
  15. package/dist/components/email-password-form.js.map +1 -0
  16. package/dist/components/index.d.ts +4 -0
  17. package/dist/components/index.js +5 -0
  18. package/dist/components/index.js.map +1 -0
  19. package/dist/components/login-panel.d.ts +13 -0
  20. package/dist/components/login-panel.js +104 -0
  21. package/dist/components/login-panel.js.map +1 -0
  22. package/dist/components/signup-panel.d.ts +13 -0
  23. package/dist/components/signup-panel.js +104 -0
  24. package/dist/components/signup-panel.js.map +1 -0
  25. package/dist/icons/ethereum.d.ts +4 -0
  26. package/dist/icons/ethereum.js +6 -0
  27. package/dist/icons/ethereum.js.map +1 -0
  28. package/dist/icons/facebook.d.ts +4 -0
  29. package/dist/icons/facebook.js +6 -0
  30. package/dist/icons/facebook.js.map +1 -0
  31. package/dist/icons/github.d.ts +4 -0
  32. package/dist/icons/github.js +6 -0
  33. package/dist/icons/github.js.map +1 -0
  34. package/dist/icons/google.d.ts +4 -0
  35. package/dist/icons/google.js +6 -0
  36. package/dist/icons/google.js.map +1 -0
  37. package/dist/icons/index.d.ts +6 -0
  38. package/dist/icons/index.js +7 -0
  39. package/dist/icons/index.js.map +1 -0
  40. package/dist/index.d.ts +24 -0
  41. package/dist/index.js +24 -0
  42. package/dist/index.js.map +1 -0
  43. package/dist/server/firebase-support.d.ts +8 -0
  44. package/dist/server/firebase-support.js +151 -0
  45. package/dist/server/firebase-support.js.map +1 -0
  46. package/dist/server/index.d.ts +4 -0
  47. package/dist/server/index.js +7 -0
  48. package/dist/server/index.js.map +1 -0
  49. package/dist/server/rest-api-handlers.d.ts +4 -0
  50. package/dist/server/rest-api-handlers.js +23 -0
  51. package/dist/server/rest-api-handlers.js.map +1 -0
  52. package/dist/server/stub-server.d.ts +14 -0
  53. package/dist/server/stub-server.js +23 -0
  54. package/dist/server/stub-server.js.map +1 -0
  55. package/dist/service/auth-service.d.ts +29 -0
  56. package/dist/service/auth-service.js +2 -0
  57. package/dist/service/auth-service.js.map +1 -0
  58. package/dist/service/context.d.ts +9 -0
  59. package/dist/service/context.js +16 -0
  60. package/dist/service/context.js.map +1 -0
  61. package/dist/service/get-singleton.d.ts +4 -0
  62. package/dist/service/get-singleton.js +24 -0
  63. package/dist/service/get-singleton.js.map +1 -0
  64. package/dist/service/impl/firebase-support.d.ts +34 -0
  65. package/dist/service/impl/firebase-support.js +190 -0
  66. package/dist/service/impl/firebase-support.js.map +1 -0
  67. package/dist/service/impl/index.d.ts +32 -0
  68. package/dist/service/impl/index.js +179 -0
  69. package/dist/service/impl/index.js.map +1 -0
  70. package/dist/service/impl/stub-auth-service.d.ts +42 -0
  71. package/dist/service/impl/stub-auth-service.js +97 -0
  72. package/dist/service/impl/stub-auth-service.js.map +1 -0
  73. package/dist/service/impl/wallet-support.d.ts +8 -0
  74. package/dist/service/impl/wallet-support.js +82 -0
  75. package/dist/service/impl/wallet-support.js.map +1 -0
  76. package/dist/service/index.d.ts +4 -0
  77. package/dist/service/index.js +4 -0
  78. package/dist/service/index.js.map +1 -0
  79. package/dist/service/provider-registry.d.ts +37 -0
  80. package/dist/service/provider-registry.js +58 -0
  81. package/dist/service/provider-registry.js.map +1 -0
  82. package/dist/types/api-response.d.ts +8 -0
  83. package/dist/types/api-response.js +2 -0
  84. package/dist/types/api-response.js.map +1 -0
  85. package/dist/types/auth-service-conf.d.ts +5 -0
  86. package/dist/types/auth-service-conf.js +2 -0
  87. package/dist/types/auth-service-conf.js.map +1 -0
  88. package/dist/types/index.d.ts +4 -0
  89. package/dist/types/index.js +2 -0
  90. package/dist/types/index.js.map +1 -0
  91. package/dist/types/libreapps-user-info-value.d.ts +6 -0
  92. package/dist/types/libreapps-user-info-value.js +2 -0
  93. package/dist/types/libreapps-user-info-value.js.map +1 -0
  94. package/dist/types/libreapps-user-info.d.ts +6 -0
  95. package/dist/types/libreapps-user-info.js +2 -0
  96. package/dist/types/libreapps-user-info.js.map +1 -0
  97. package/dist/util/analytics.d.ts +9 -0
  98. package/dist/util/analytics.js +10 -0
  99. package/dist/util/analytics.js.map +1 -0
  100. package/icons/ethereum.tsx +18 -0
  101. package/icons/facebook.tsx +11 -0
  102. package/icons/github.tsx +14 -0
  103. package/icons/google.tsx +13 -0
  104. package/icons/index.ts +16 -0
  105. package/index.ts +51 -0
  106. package/libreapps-ui.d.ts +23 -0
  107. package/package.json +57 -0
  108. package/server/firebase-support.ts +176 -0
  109. package/server/index.ts +14 -0
  110. package/server/rest-api-handlers.ts +33 -0
  111. package/server/stub-server.ts +28 -0
  112. package/service/auth-service.ts +21 -0
  113. package/service/context.tsx +46 -0
  114. package/service/get-singleton.ts +37 -0
  115. package/service/impl/firebase-support.ts +241 -0
  116. package/service/impl/index.ts +231 -0
  117. package/service/impl/stub-auth-service.ts +131 -0
  118. package/service/impl/wallet-support.ts +100 -0
  119. package/service/index.ts +11 -0
  120. package/service/provider-registry.ts +71 -0
  121. package/tsconfig.json +15 -0
  122. package/types/api-response.ts +5 -0
  123. package/types/auth-service-conf.ts +9 -0
  124. package/types/index.ts +6 -0
  125. package/types/libreapps-user-info-value.ts +9 -0
  126. package/types/libreapps-user-info.ts +9 -0
  127. package/util/analytics.ts +21 -0
@@ -0,0 +1,4 @@
1
+ import React from 'react';
2
+ import { type LucideProps } from 'lucide-react';
3
+ declare const GitHub: React.FC<LucideProps>;
4
+ export default GitHub;
@@ -0,0 +1,6 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import React from 'react';
3
+ import {} from 'lucide-react';
4
+ const GitHub = (props) => (_jsx("svg", { viewBox: "0 0 438.549 438.549", ...props, children: _jsx("path", { fill: "currentColor", d: "M409.132 114.573c-19.608-33.596-46.205-60.194-79.798-79.8-33.598-19.607-70.277-29.408-110.063-29.408-39.781 0-76.472 9.804-110.063 29.408-33.596 19.605-60.192 46.204-79.8 79.8C9.803 148.168 0 184.854 0 224.63c0 47.78 13.94 90.745 41.827 128.906 27.884 38.164 63.906 64.572 108.063 79.227 5.14.954 8.945.283 11.419-1.996 2.475-2.282 3.711-5.14 3.711-8.562 0-.571-.049-5.708-.144-15.417a2549.81 2549.81 0 01-.144-25.406l-6.567 1.136c-4.187.767-9.469 1.092-15.846 1-6.374-.089-12.991-.757-19.842-1.999-6.854-1.231-13.229-4.086-19.13-8.559-5.898-4.473-10.085-10.328-12.56-17.556l-2.855-6.57c-1.903-4.374-4.899-9.233-8.992-14.559-4.093-5.331-8.232-8.945-12.419-10.848l-1.999-1.431c-1.332-.951-2.568-2.098-3.711-3.429-1.142-1.331-1.997-2.663-2.568-3.997-.572-1.335-.098-2.43 1.427-3.289 1.525-.859 4.281-1.276 8.28-1.276l5.708.853c3.807.763 8.516 3.042 14.133 6.851 5.614 3.806 10.229 8.754 13.846 14.842 4.38 7.806 9.657 13.754 15.846 17.847 6.184 4.093 12.419 6.136 18.699 6.136 6.28 0 11.704-.476 16.274-1.423 4.565-.952 8.848-2.383 12.847-4.285 1.713-12.758 6.377-22.559 13.988-29.41-10.848-1.14-20.601-2.857-29.264-5.14-8.658-2.286-17.605-5.996-26.835-11.14-9.235-5.137-16.896-11.516-22.985-19.126-6.09-7.614-11.088-17.61-14.987-29.979-3.901-12.374-5.852-26.648-5.852-42.826 0-23.035 7.52-42.637 22.557-58.817-7.044-17.318-6.379-36.732 1.997-58.24 5.52-1.715 13.706-.428 24.554 3.853 10.85 4.283 18.794 7.952 23.84 10.994 5.046 3.041 9.089 5.618 12.135 7.708 17.705-4.947 35.976-7.421 54.818-7.421s37.117 2.474 54.823 7.421l10.849-6.849c7.419-4.57 16.18-8.758 26.262-12.565 10.088-3.805 17.802-4.853 23.134-3.138 8.562 21.509 9.325 40.922 2.279 58.24 15.036 16.18 22.559 35.787 22.559 58.817 0 16.178-1.958 30.497-5.853 42.966-3.9 12.471-8.941 22.457-15.125 29.979-6.191 7.521-13.901 13.85-23.131 18.986-9.232 5.14-18.182 8.85-26.84 11.136-8.662 2.286-18.415 4.004-29.263 5.146 9.894 8.562 14.842 22.077 14.842 40.539v60.237c0 3.422 1.19 6.279 3.572 8.562 2.379 2.279 6.136 2.95 11.276 1.995 44.163-14.653 80.185-41.062 108.068-79.226 27.88-38.161 41.825-81.126 41.825-128.906-.01-39.771-9.818-76.454-29.414-110.049z" }) }));
5
+ export default GitHub;
6
+ //# sourceMappingURL=github.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"github.js","sourceRoot":"","sources":["../../icons/github.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAoB,MAAM,cAAc,CAAA;AAG/C,MAAM,MAAM,GAA0B,CAAC,KAAkB,EAAE,EAAE,CAAC,CAC5D,cAAK,OAAO,EAAC,qBAAqB,KAAK,KAAK,YAC1C,eACE,IAAI,EAAC,cAAc,EACnB,CAAC,EAAC,qkEAAqkE,GACjkE,GACJ,CACP,CAAA;AAED,eAAe,MAAM,CAAA"}
@@ -0,0 +1,4 @@
1
+ import React from 'react';
2
+ import { type LucideProps } from 'lucide-react';
3
+ declare const Google: React.FC<LucideProps>;
4
+ export default Google;
@@ -0,0 +1,6 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import React from 'react';
3
+ import {} from 'lucide-react';
4
+ const Google = (props) => (_jsxs("svg", { viewBox: "0 0 32 32", fill: "none", xmlns: "http://www.w3.org/2000/svg", ...props, children: [_jsx("path", { d: "M30.0014 16.3109C30.0014 15.1598 29.9061 14.3198 29.6998 13.4487H16.2871V18.6442H24.1601C24.0014 19.9354 23.1442 21.8798 21.2394 23.1864L21.2127 23.3604L25.4536 26.58L25.7474 26.6087C28.4458 24.1665 30.0014 20.5731 30.0014 16.3109Z", fill: "#4285F4" }), _jsx("path", { d: "M16.2863 29.9998C20.1434 29.9998 23.3814 28.7553 25.7466 26.6086L21.2386 23.1863C20.0323 24.0108 18.4132 24.5863 16.2863 24.5863C12.5086 24.5863 9.30225 22.1441 8.15929 18.7686L7.99176 18.7825L3.58208 22.127L3.52441 22.2841C5.87359 26.8574 10.699 29.9998 16.2863 29.9998Z", fill: "#34A853" }), _jsx("path", { d: "M8.15964 18.769C7.85806 17.8979 7.68352 16.9645 7.68352 16.0001C7.68352 15.0356 7.85806 14.1023 8.14377 13.2312L8.13578 13.0456L3.67083 9.64746L3.52475 9.71556C2.55654 11.6134 2.00098 13.7445 2.00098 16.0001C2.00098 18.2556 2.55654 20.3867 3.52475 22.2845L8.15964 18.769Z", fill: "#FBBC05" }), _jsx("path", { d: "M16.2864 7.4133C18.9689 7.4133 20.7784 8.54885 21.8102 9.4978L25.8419 5.64C23.3658 3.38445 20.1435 2 16.2864 2C10.699 2 5.8736 5.1422 3.52441 9.71549L8.14345 13.2311C9.30229 9.85555 12.5086 7.4133 16.2864 7.4133Z", fill: "#EB4335" })] }));
5
+ export default Google;
6
+ //# sourceMappingURL=google.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"google.js","sourceRoot":"","sources":["../../icons/google.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAoB,MAAM,cAAc,CAAA;AAE/C,MAAM,MAAM,GAA0B,CAAC,KAAkB,EAAE,EAAE,CAAC,CAC5D,eAAK,OAAO,EAAC,WAAW,EAAC,IAAI,EAAC,MAAM,EAAC,KAAK,EAAC,4BAA4B,KAAK,KAAK,aAC/E,eAAM,CAAC,EAAC,yOAAyO,EAAC,IAAI,EAAC,SAAS,GAAE,EAClQ,eAAM,CAAC,EAAC,iRAAiR,EAAC,IAAI,EAAC,SAAS,GAAE,EAC1S,eAAM,CAAC,EAAC,iRAAiR,EAAC,IAAI,EAAC,SAAS,GAAE,EAC1S,eAAM,CAAC,EAAC,sNAAsN,EAAC,IAAI,EAAC,SAAS,GAAE,IAC3O,CACP,CAAA;AAED,eAAe,MAAM,CAAA"}
@@ -0,0 +1,6 @@
1
+ import { ArrowLeft } from 'lucide-react';
2
+ import Google from './google';
3
+ import Facebook from './facebook';
4
+ import GitHub from './github';
5
+ import Ethereum from './ethereum';
6
+ export { Google, Facebook, GitHub, ArrowLeft, Ethereum };
@@ -0,0 +1,7 @@
1
+ import { ArrowLeft } from 'lucide-react';
2
+ import Google from './google';
3
+ import Facebook from './facebook';
4
+ import GitHub from './github';
5
+ import Ethereum from './ethereum';
6
+ export { Google, Facebook, GitHub, ArrowLeft, Ethereum };
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../icons/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAExC,OAAO,MAAM,MAAM,UAAU,CAAA;AAC7B,OAAO,QAAQ,MAAM,YAAY,CAAA;AACjC,OAAO,MAAM,MAAM,UAAU,CAAA;AAC7B,OAAO,QAAQ,MAAM,YAAY,CAAA;AAEjC,OAAO,EACL,MAAM,EACN,QAAQ,EACR,MAAM,EACN,SAAS,EACT,QAAQ,EACT,CAAA"}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * @libreapps/auth
3
+ *
4
+ * Pluggable authentication library.
5
+ * Firebase support available via @libreapps/auth-firebase (optional).
6
+ *
7
+ * Usage without Firebase:
8
+ * The auth system works out of the box with a stub implementation.
9
+ * All auth operations will return graceful failures.
10
+ *
11
+ * Usage with Firebase:
12
+ * ```ts
13
+ * import { FirebaseAuthService } from '@libreapps/auth-firebase'
14
+ * import { registerAuthProvider } from '@libreapps/auth'
15
+ *
16
+ * registerAuthProvider('firebase', FirebaseAuthService)
17
+ * ```
18
+ */
19
+ export type { LibreAppsUserInfo, LibreAppsUserInfoValue, AuthServiceConf, APIResponse } from './types';
20
+ export type { AuthService, AuthProvider } from './service';
21
+ export { useAuth, AuthServiceProvider, registerAuthProvider, setActiveProvider, getActiveProvider, hasAuthProvider, getRegisteredProviders, StubAuthService } from './service';
22
+ export type { AuthServiceFactory } from './service';
23
+ export { LoginPanel, EmailPasswordForm, AuthWidget, SignupPanel } from './components';
24
+ export * from './icons';
package/dist/index.js ADDED
@@ -0,0 +1,24 @@
1
+ /**
2
+ * @libreapps/auth
3
+ *
4
+ * Pluggable authentication library.
5
+ * Firebase support available via @libreapps/auth-firebase (optional).
6
+ *
7
+ * Usage without Firebase:
8
+ * The auth system works out of the box with a stub implementation.
9
+ * All auth operations will return graceful failures.
10
+ *
11
+ * Usage with Firebase:
12
+ * ```ts
13
+ * import { FirebaseAuthService } from '@libreapps/auth-firebase'
14
+ * import { registerAuthProvider } from '@libreapps/auth'
15
+ *
16
+ * registerAuthProvider('firebase', FirebaseAuthService)
17
+ * ```
18
+ */
19
+ export { useAuth, AuthServiceProvider, registerAuthProvider, setActiveProvider, getActiveProvider, hasAuthProvider, getRegisteredProviders, StubAuthService } from './service';
20
+ // Components
21
+ export { LoginPanel, EmailPasswordForm, AuthWidget, SignupPanel } from './components';
22
+ // Icons
23
+ export * from './icons';
24
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAYH,OAAO,EACL,OAAO,EACP,mBAAmB,EACnB,oBAAoB,EACpB,iBAAiB,EACjB,iBAAiB,EACjB,eAAe,EACf,sBAAsB,EACtB,eAAe,EAChB,MAAM,WAAW,CAAA;AAGlB,aAAa;AACb,OAAO,EACL,UAAU,EACV,iBAAiB,EACjB,UAAU,EACV,WAAW,EACZ,MAAM,cAAc,CAAA;AAErB,QAAQ;AACR,cAAc,SAAS,CAAA"}
@@ -0,0 +1,8 @@
1
+ import type { LibreAppsUserInfoValue } from '../types';
2
+ export declare function getUserServerSide(): Promise<LibreAppsUserInfoValue | null>;
3
+ export declare const generateCustomToken: () => Promise<{
4
+ success: boolean;
5
+ token: string | null;
6
+ }>;
7
+ export declare function createSessionCookie(idToken: string, sessionCookieOptions: any): Promise<string>;
8
+ export declare function revokeAllSessions(session: string): Promise<void>;
@@ -0,0 +1,151 @@
1
+ // Server-side Firebase authentication
2
+ // For static builds, these functions return null/false
3
+ // These functions require server-side environment (not available in static export)
4
+ // They will return null/false gracefully when running in static context
5
+ export async function getUserServerSide() {
6
+ // Check if we're in a server environment with the required modules
7
+ if (typeof window !== 'undefined') {
8
+ // Client-side: auth should be handled via client-side Firebase
9
+ return null;
10
+ }
11
+ try {
12
+ // Dynamic imports to prevent bundling issues in static export
13
+ const { cookies } = await import('next/headers');
14
+ const { initializeApp, getApps, cert } = await import('firebase-admin/app');
15
+ const { getAuth } = await import('firebase-admin/auth');
16
+ const { getFirestore } = await import('firebase-admin/firestore');
17
+ const hasValidCredentials = process.env.FIREBASE_CLIENT_EMAIL &&
18
+ process.env.FIREBASE_PROJECT_ID &&
19
+ process.env.FIREBASE_PRIVATE_KEY;
20
+ if (!hasValidCredentials) {
21
+ console.warn('Firebase credentials not configured');
22
+ return null;
23
+ }
24
+ const firebaseApp = getApps().find((it) => it.name === 'firebase-admin-app') ||
25
+ initializeApp({
26
+ credential: cert({
27
+ clientEmail: process.env.FIREBASE_CLIENT_EMAIL,
28
+ projectId: process.env.FIREBASE_PROJECT_ID,
29
+ privateKey: process.env.FIREBASE_PRIVATE_KEY.replace(/\\n/g, '\n')
30
+ }),
31
+ }, 'firebase-admin-app');
32
+ const auth = getAuth(firebaseApp);
33
+ const db = getFirestore(firebaseApp, 'accounts');
34
+ const c = await cookies();
35
+ const session = c.get('__session')?.value;
36
+ if (!session)
37
+ return null;
38
+ try {
39
+ const isRevoked = !(await auth.verifySessionCookie(session, true));
40
+ if (isRevoked)
41
+ return null;
42
+ }
43
+ catch {
44
+ return null;
45
+ }
46
+ const decodedIdToken = await auth.verifySessionCookie(session);
47
+ const currentUser = await auth.getUser(decodedIdToken.uid);
48
+ const walletAddress = await db.collection('USER_INFO').doc(currentUser.email ?? '').get();
49
+ return {
50
+ email: currentUser.email ?? '',
51
+ displayName: currentUser.displayName ?? null,
52
+ walletAddress: walletAddress.get('walletAddress') ?? null,
53
+ };
54
+ }
55
+ catch (error) {
56
+ console.warn('Server-side auth not available:', error);
57
+ return null;
58
+ }
59
+ }
60
+ export const generateCustomToken = async () => {
61
+ // For static builds, this functionality is not available
62
+ if (typeof window !== 'undefined') {
63
+ return { success: false, token: null };
64
+ }
65
+ try {
66
+ const { cookies } = await import('next/headers');
67
+ const { initializeApp, getApps, cert } = await import('firebase-admin/app');
68
+ const { getAuth } = await import('firebase-admin/auth');
69
+ const hasValidCredentials = process.env.FIREBASE_CLIENT_EMAIL &&
70
+ process.env.FIREBASE_PROJECT_ID &&
71
+ process.env.FIREBASE_PRIVATE_KEY;
72
+ if (!hasValidCredentials) {
73
+ return { success: false, token: null };
74
+ }
75
+ const firebaseApp = getApps().find((it) => it.name === 'firebase-admin-app') ||
76
+ initializeApp({
77
+ credential: cert({
78
+ clientEmail: process.env.FIREBASE_CLIENT_EMAIL,
79
+ projectId: process.env.FIREBASE_PROJECT_ID,
80
+ privateKey: process.env.FIREBASE_PRIVATE_KEY.replace(/\\n/g, '\n')
81
+ }),
82
+ }, 'firebase-admin-app');
83
+ const auth = getAuth(firebaseApp);
84
+ const c = await cookies();
85
+ const session = c.get('__session')?.value;
86
+ if (!session)
87
+ return { success: false, token: null };
88
+ const decodedIdToken = await auth.verifySessionCookie(session);
89
+ const currentUser = await auth.getUser(decodedIdToken.uid);
90
+ const token = await auth.createCustomToken(currentUser.uid);
91
+ return { success: true, token };
92
+ }
93
+ catch (error) {
94
+ console.warn('Token generation not available:', error);
95
+ return { success: false, token: null };
96
+ }
97
+ };
98
+ export async function createSessionCookie(idToken, sessionCookieOptions) {
99
+ try {
100
+ const { initializeApp, getApps, cert } = await import('firebase-admin/app');
101
+ const { getAuth } = await import('firebase-admin/auth');
102
+ const hasValidCredentials = process.env.FIREBASE_CLIENT_EMAIL &&
103
+ process.env.FIREBASE_PROJECT_ID &&
104
+ process.env.FIREBASE_PRIVATE_KEY;
105
+ if (!hasValidCredentials) {
106
+ throw new Error('Firebase not configured');
107
+ }
108
+ const firebaseApp = getApps().find((it) => it.name === 'firebase-admin-app') ||
109
+ initializeApp({
110
+ credential: cert({
111
+ clientEmail: process.env.FIREBASE_CLIENT_EMAIL,
112
+ projectId: process.env.FIREBASE_PROJECT_ID,
113
+ privateKey: process.env.FIREBASE_PRIVATE_KEY.replace(/\\n/g, '\n')
114
+ }),
115
+ }, 'firebase-admin-app');
116
+ const auth = getAuth(firebaseApp);
117
+ return auth.createSessionCookie(idToken, sessionCookieOptions);
118
+ }
119
+ catch (error) {
120
+ console.warn('Session cookie creation not available:', error);
121
+ throw error;
122
+ }
123
+ }
124
+ export async function revokeAllSessions(session) {
125
+ try {
126
+ const { initializeApp, getApps, cert } = await import('firebase-admin/app');
127
+ const { getAuth } = await import('firebase-admin/auth');
128
+ const hasValidCredentials = process.env.FIREBASE_CLIENT_EMAIL &&
129
+ process.env.FIREBASE_PROJECT_ID &&
130
+ process.env.FIREBASE_PRIVATE_KEY;
131
+ if (!hasValidCredentials) {
132
+ throw new Error('Firebase not configured');
133
+ }
134
+ const firebaseApp = getApps().find((it) => it.name === 'firebase-admin-app') ||
135
+ initializeApp({
136
+ credential: cert({
137
+ clientEmail: process.env.FIREBASE_CLIENT_EMAIL,
138
+ projectId: process.env.FIREBASE_PROJECT_ID,
139
+ privateKey: process.env.FIREBASE_PRIVATE_KEY.replace(/\\n/g, '\n')
140
+ }),
141
+ }, 'firebase-admin-app');
142
+ const auth = getAuth(firebaseApp);
143
+ const decodedIdToken = await auth.verifySessionCookie(session);
144
+ return await auth.revokeRefreshTokens(decodedIdToken.sub);
145
+ }
146
+ catch (error) {
147
+ console.warn('Session revocation not available:', error);
148
+ throw error;
149
+ }
150
+ }
151
+ //# sourceMappingURL=firebase-support.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"firebase-support.js","sourceRoot":"","sources":["../../server/firebase-support.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,uDAAuD;AAIvD,mFAAmF;AACnF,wEAAwE;AAExE,MAAM,CAAC,KAAK,UAAU,iBAAiB;IACrC,mEAAmE;IACnE,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;QAClC,+DAA+D;QAC/D,OAAO,IAAI,CAAA;IACb,CAAC;IAED,IAAI,CAAC;QACH,8DAA8D;QAC9D,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,MAAM,CAAC,cAAc,CAAC,CAAA;QAChD,MAAM,EAAE,aAAa,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,MAAM,MAAM,CAAC,oBAAoB,CAAC,CAAA;QAE3E,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,MAAM,CAAC,qBAAqB,CAAC,CAAA;QACvD,MAAM,EAAE,YAAY,EAAE,GAAG,MAAM,MAAM,CAAC,0BAA0B,CAAC,CAAA;QAEjE,MAAM,mBAAmB,GAAG,OAAO,CAAC,GAAG,CAAC,qBAAqB;YAC3D,OAAO,CAAC,GAAG,CAAC,mBAAmB;YAC/B,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAA;QAElC,IAAI,CAAC,mBAAmB,EAAE,CAAC;YACzB,OAAO,CAAC,IAAI,CAAC,qCAAqC,CAAC,CAAA;YACnD,OAAO,IAAI,CAAA;QACb,CAAC;QAED,MAAM,WAAW,GAAG,OAAO,EAAE,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,E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,CAAC,GAAG,CAAC,qBAAqB;YAC3D,OAAO,CAAC,GAAG,CAAC,mBAAmB;YAC/B,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAA;QAElC,IAAI,CAAC,mBAAmB,EAAE,CAAC;YACzB,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAA;QAC5C,CAAC;QAED,MAAM,WAAW,GAAG,OAAO,EAAE,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,IAAI,KAAK,oBAAoB,CAAC;YAC1E,aAAa,CAAC;gBACZ,UAAU,EAAE,IAAI,CAAC;oBACf,WAAW,EAAE,OAAO,CAAC,GAAG,CAAC,qBAAqB;oBAC9C,SAAS,EAAE,OAAO,CAAC,GAAG,CAAC,mBAAmB;oBAC1C,UAAU,EAAE,OAAO,CAAC,GAAG,CAAC,oBAAqB,CAAC,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC;iBACpE,CAAC;aACH,EAAE,oBAAoB,CAAC,CAAA;QAE1B,MAAM,IAAI,GAAG,OAAO,CAAC,WAAW,CAAC,CAAA;QACjC,MAAM,cAAc,GAAG,MAAM,IAAI,CAAC,mBAAmB,CAAC,OAAO,CAAC,CAAA;QAC9D,OAAO,MAAM,IAAI,CAAC,mBAAmB,CAAC,cAAc,CAAC,GAAG,CAAC,CAAA;IAC3D,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,IAAI,CAAC,mCAAmC,EAAE,KAAK,CAAC,CAAA;QACxD,MAAM,KAAK,CAAA;IACb,CAAC;AACH,CAAC"}
@@ -0,0 +1,4 @@
1
+ export { getUserServerSide, generateCustomToken, createSessionCookie, revokeAllSessions } from './firebase-support';
2
+ export { handleLogin as handleLoginApiRequest, handleLogout as handleLogoutApiRequest } from './rest-api-handlers';
3
+ export type { APIResponse } from '../types';
4
+ export { getUserServerSide as stubGetUserServerSide, generateCustomToken as stubGenerateCustomToken } from './stub-server';
@@ -0,0 +1,7 @@
1
+ // Server-side auth functions - use Firebase if configured, otherwise stub
2
+ // For Firebase support, also install @libreapps/auth-firebase
3
+ export { getUserServerSide, generateCustomToken, createSessionCookie, revokeAllSessions } from './firebase-support';
4
+ export { handleLogin as handleLoginApiRequest, handleLogout as handleLogoutApiRequest } from './rest-api-handlers';
5
+ // Re-export stub for explicit use
6
+ export { getUserServerSide as stubGetUserServerSide, generateCustomToken as stubGenerateCustomToken } from './stub-server';
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../server/index.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,8DAA8D;AAC9D,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AACnH,OAAO,EACL,WAAW,IAAI,qBAAqB,EACpC,YAAY,IAAI,sBAAsB,EACvC,MAAM,qBAAqB,CAAA;AAG5B,kCAAkC;AAClC,OAAO,EACL,iBAAiB,IAAI,qBAAqB,EAC1C,mBAAmB,IAAI,uBAAuB,EAC/C,MAAM,eAAe,CAAA"}
@@ -0,0 +1,4 @@
1
+ import { NextRequest, NextResponse } from 'next/server';
2
+ import type { APIResponse } from '../types';
3
+ export declare function handleLogin(request: NextRequest): Promise<NextResponse<APIResponse<string>>>;
4
+ export declare function handleLogout(): Promise<NextResponse<APIResponse<string>>>;
@@ -0,0 +1,23 @@
1
+ import { cookies } from 'next/headers';
2
+ import { NextRequest, NextResponse } from 'next/server';
3
+ import { createSessionCookie, revokeAllSessions } from './firebase-support';
4
+ export async function handleLogin(request) {
5
+ const reqBody = (await request.json());
6
+ const idToken = reqBody.idToken;
7
+ const expiresIn = 60 * 60 * 24 * 5 * 1000; // 5 days
8
+ const sessionCookie = await createSessionCookie(idToken, { expiresIn });
9
+ const c = await cookies();
10
+ c.set('__session', sessionCookie, { maxAge: expiresIn, httpOnly: true, secure: true });
11
+ return NextResponse.json({ success: true, data: 'Signed in successfully.' });
12
+ }
13
+ export async function handleLogout() {
14
+ const c = await cookies();
15
+ const sessionCookie = c.get('__session')?.value;
16
+ if (!sessionCookie) {
17
+ return NextResponse.json({ success: false, error: 'Session not found.' }, { status: 400 });
18
+ }
19
+ c.delete('__session');
20
+ await revokeAllSessions(sessionCookie);
21
+ return NextResponse.json({ success: true, data: 'Signed out successfully.' });
22
+ }
23
+ //# sourceMappingURL=rest-api-handlers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rest-api-handlers.js","sourceRoot":"","sources":["../../server/rest-api-handlers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtC,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AACvD,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AAG3E,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,OAAoB;IACpD,MAAM,OAAO,GAAG,CAAC,MAAM,OAAO,CAAC,IAAI,EAAE,CAAwB,CAAA;IAC7D,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAA;IAE/B,MAAM,SAAS,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,GAAG,IAAI,CAAA,CAAC,SAAS;IAEnD,MAAM,aAAa,GAAG,MAAM,mBAAmB,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,CAAC,CAAA;IAEvE,MAAM,CAAC,GAAG,MAAM,OAAO,EAAE,CAAA;IACzB,CAAC,CAAC,GAAG,CAAC,WAAW,EAAE,aAAa,EAAE,EAAE,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAA;IAEtF,OAAO,YAAY,CAAC,IAAI,CAAsB,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,yBAAyB,EAAE,CAAC,CAAA;AACnG,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,YAAY;IAChC,MAAM,CAAC,GAAG,MAAM,OAAO,EAAE,CAAA;IACzB,MAAM,aAAa,GAAG,CAAC,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,KAAK,CAAA;IAE/C,IAAI,CAAC,aAAa,EAAE,CAAC;QACnB,OAAO,YAAY,CAAC,IAAI,CAAsB,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,oBAAoB,EAAE,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,CAAA;IACjH,CAAC;IAED,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,CAAA;IAErB,MAAM,iBAAiB,CAAC,aAAa,CAAC,CAAA;IAEtC,OAAO,YAAY,CAAC,IAAI,CAAsB,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,0BAA0B,EAAE,CAAC,CAAA;AACpG,CAAC"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Stub Server-side Authentication
3
+ *
4
+ * Used when Firebase Admin is not configured.
5
+ * All functions return null/false gracefully.
6
+ */
7
+ import type { LibreAppsUserInfoValue } from '../types';
8
+ export declare function getUserServerSide(): Promise<LibreAppsUserInfoValue | null>;
9
+ export declare function generateCustomToken(): Promise<{
10
+ success: boolean;
11
+ token: string | null;
12
+ }>;
13
+ export declare function createSessionCookie(_idToken: string, _sessionCookieOptions: any): Promise<string>;
14
+ export declare function revokeAllSessions(_session: string): Promise<void>;
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Stub Server-side Authentication
3
+ *
4
+ * Used when Firebase Admin is not configured.
5
+ * All functions return null/false gracefully.
6
+ */
7
+ export async function getUserServerSide() {
8
+ console.warn('Server-side auth not configured. Install @libreapps/auth-firebase for Firebase support.');
9
+ return null;
10
+ }
11
+ export async function generateCustomToken() {
12
+ console.warn('Server-side auth not configured. Install @libreapps/auth-firebase for Firebase support.');
13
+ return { success: false, token: null };
14
+ }
15
+ export async function createSessionCookie(_idToken, _sessionCookieOptions) {
16
+ console.warn('Server-side auth not configured. Install @libreapps/auth-firebase for Firebase support.');
17
+ throw new Error('Auth provider not configured');
18
+ }
19
+ export async function revokeAllSessions(_session) {
20
+ console.warn('Server-side auth not configured. Install @libreapps/auth-firebase for Firebase support.');
21
+ throw new Error('Auth provider not configured');
22
+ }
23
+ //# sourceMappingURL=stub-server.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stub-server.js","sourceRoot":"","sources":["../../server/stub-server.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,MAAM,CAAC,KAAK,UAAU,iBAAiB;IACrC,OAAO,CAAC,IAAI,CAAC,yFAAyF,CAAC,CAAA;IACvG,OAAO,IAAI,CAAA;AACb,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,mBAAmB;IACvC,OAAO,CAAC,IAAI,CAAC,yFAAyF,CAAC,CAAA;IACvG,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,CAAA;AACxC,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,mBAAmB,CAAC,QAAgB,EAAE,qBAA0B;IACpF,OAAO,CAAC,IAAI,CAAC,yFAAyF,CAAC,CAAA;IACvG,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAA;AACjD,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,QAAgB;IACtD,OAAO,CAAC,IAAI,CAAC,yFAAyF,CAAC,CAAA;IACvG,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAA;AACjD,CAAC"}
@@ -0,0 +1,29 @@
1
+ import type { LibreAppsUserInfo } from "../types";
2
+ type AuthProvider = 'google' | 'facebook' | 'github';
3
+ interface AuthService {
4
+ get loggedIn(): boolean;
5
+ get user(): LibreAppsUserInfo | null;
6
+ signupEmailAndPassword: (email: string, password: string) => Promise<{
7
+ success: boolean;
8
+ userInfo: LibreAppsUserInfo | null;
9
+ message?: string;
10
+ }>;
11
+ loginEmailAndPassword: (email: string, password: string) => Promise<{
12
+ success: boolean;
13
+ userInfo: LibreAppsUserInfo | null;
14
+ message?: string;
15
+ }>;
16
+ loginWithProvider: (provider: AuthProvider) => Promise<{
17
+ success: boolean;
18
+ userInfo: LibreAppsUserInfo | null;
19
+ }>;
20
+ loginWithCustomToken: (token: string) => Promise<{
21
+ success: boolean;
22
+ userInfo: LibreAppsUserInfo | null;
23
+ }>;
24
+ associateWallet: () => Promise<void>;
25
+ logout: () => Promise<{
26
+ success: boolean;
27
+ }>;
28
+ }
29
+ export { type AuthService as default, type AuthProvider };
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=auth-service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth-service.js","sourceRoot":"","sources":["../../service/auth-service.ts"],"names":[],"mappings":"AAiBA,OAAO,EAGN,CAAA"}
@@ -0,0 +1,9 @@
1
+ import React, { type PropsWithChildren } from 'react';
2
+ import type { AuthServiceConf, LibreAppsUserInfoValue } from '../types';
3
+ import type AuthService from './auth-service';
4
+ declare const useAuth: () => AuthService;
5
+ declare const AuthServiceProvider: React.FC<PropsWithChildren & {
6
+ conf: AuthServiceConf;
7
+ user: LibreAppsUserInfoValue | null;
8
+ }>;
9
+ export { AuthServiceProvider, useAuth };
@@ -0,0 +1,16 @@
1
+ 'use client';
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import React, { useContext } from 'react';
4
+ import getSingleton from './get-singleton';
5
+ const AuthServiceContext = React.createContext(undefined);
6
+ /* PLEASE LEAVE
7
+ const _log = (s: string) => {
8
+ const d = new Date()
9
+ console.log(`TIMESTAMPED: ${d.getUTCMinutes()}:${d.getUTCSeconds()}:${d.getUTCMilliseconds()}`)
10
+ console.log(s)
11
+ }
12
+ */
13
+ const useAuth = () => useContext(AuthServiceContext);
14
+ const AuthServiceProvider = ({ children, user, conf }) => (_jsx(AuthServiceContext.Provider, { value: getSingleton(conf, user), children: children }));
15
+ export { AuthServiceProvider, useAuth };
16
+ //# sourceMappingURL=context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.js","sourceRoot":"","sources":["../../service/context.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAEZ,OAAO,KAAK,EAAE,EACZ,UAAU,EAEX,MAAM,OAAO,CAAA;AAId,OAAO,YAAY,MAAM,iBAAiB,CAAA;AAE1C,MAAM,kBAAkB,GAAG,KAAK,CAAC,aAAa,CAA0B,SAAS,CAAC,CAAA;AAElF;;;;;;EAME;AAEF,MAAM,OAAO,GAAG,GAAgB,EAAE,CAChC,UAAU,CAAC,kBAAkB,CAC9B,CAAA;AAED,MAAM,mBAAmB,GAKrB,CAAC,EACH,QAAQ,EACR,IAAI,EACJ,IAAI,EACL,EAAE,EAAE,CAAC,CACJ,KAAC,kBAAkB,CAAC,QAAQ,IAAC,KAAK,EAAE,YAAY,CAAC,IAAI,EAAE,IAAI,CAAC,YACzD,QAAQ,GACmB,CAC/B,CAAA;AAGD,OAAO,EACL,mBAAmB,EACnB,OAAO,EACR,CAAA"}
@@ -0,0 +1,4 @@
1
+ import type AuthService from './auth-service';
2
+ import type { AuthServiceConf, LibreAppsUserInfoValue } from '../types';
3
+ declare const getSingleton: (conf: AuthServiceConf, serverSideUser: LibreAppsUserInfoValue | null) => AuthService;
4
+ export default getSingleton;
@@ -0,0 +1,24 @@
1
+ import { enableStaticRendering } from 'mobx-react-lite';
2
+ import { getActiveProvider } from './provider-registry';
3
+ import { StubAuthService } from './impl/stub-auth-service';
4
+ enableStaticRendering(typeof window === "undefined");
5
+ // https://dev.to/ivandotv/mobx-server-side-rendering-with-next-js-4m18
6
+ let instance = undefined;
7
+ const getSingleton = (conf, serverSideUser) => {
8
+ // Get the registered auth provider, or use stub if none configured
9
+ const AuthServiceClass = getActiveProvider() ?? StubAuthService;
10
+ // For server side rendering always create a new store
11
+ if (typeof window === "undefined") {
12
+ return new AuthServiceClass(conf, serverSideUser);
13
+ }
14
+ // Client side, create the store only once in the client
15
+ if (!instance) {
16
+ instance = new AuthServiceClass(conf, serverSideUser);
17
+ }
18
+ else if ('setServerSideUser' in instance && typeof instance.setServerSideUser === 'function') {
19
+ instance.setServerSideUser(serverSideUser);
20
+ }
21
+ return instance;
22
+ };
23
+ export default getSingleton;
24
+ //# sourceMappingURL=get-singleton.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-singleton.js","sourceRoot":"","sources":["../../service/get-singleton.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAA;AAIvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAE1D,qBAAqB,CAAC,OAAO,MAAM,KAAK,WAAW,CAAC,CAAA;AAEpD,uEAAuE;AACvE,IAAI,QAAQ,GAA4B,SAAS,CAAA;AAEjD,MAAM,YAAY,GAAG,CACnB,IAAqB,EACrB,cAA6C,EAChC,EAAE;IAEf,mEAAmE;IACnE,MAAM,gBAAgB,GAAG,iBAAiB,EAAE,IAAI,eAAe,CAAA;IAE/D,sDAAsD;IACtD,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;QAClC,OAAO,IAAI,gBAAgB,CAAC,IAAI,EAAE,cAAc,CAAC,CAAA;IACnD,CAAC;IAED,wDAAwD;IACxD,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,QAAQ,GAAG,IAAI,gBAAgB,CAAC,IAAI,EAAE,cAAc,CAAC,CAAA;IACvD,CAAC;SACI,IAAI,mBAAmB,IAAI,QAAQ,IAAI,OAAO,QAAQ,CAAC,iBAAiB,KAAK,UAAU,EAAE,CAAC;QAC7F,QAAQ,CAAC,iBAAiB,CAAC,cAAc,CAAC,CAAA;IAC5C,CAAC;IAED,OAAO,QAAQ,CAAA;AACjB,CAAC,CAAA;AAED,eAAe,YAAY,CAAA"}
@@ -0,0 +1,34 @@
1
+ import { type User, type Auth } from 'firebase/auth';
2
+ import { type Firestore } from 'firebase/firestore';
3
+ export declare const firebaseConfig: {
4
+ apiKey: string | undefined;
5
+ authDomain: string | undefined;
6
+ projectId: string | undefined;
7
+ storageBucket: string | undefined;
8
+ messagingSenderId: string | undefined;
9
+ appId: string | undefined;
10
+ };
11
+ declare let auth: Auth | null;
12
+ declare let db: Firestore | null;
13
+ export { auth, db };
14
+ export declare function loginWithProvider(provider: string): Promise<{
15
+ success: boolean;
16
+ user: User | null;
17
+ }>;
18
+ export declare function signupWithEmailAndPassword(email: string, password: string): Promise<{
19
+ success: boolean;
20
+ user?: User;
21
+ message?: string;
22
+ }>;
23
+ export declare function loginWithEmailAndPassword(email: string, password: string): Promise<{
24
+ success: boolean;
25
+ user?: User;
26
+ message?: string;
27
+ }>;
28
+ export declare function loginWithCustomToken(token: string): Promise<{
29
+ success: boolean;
30
+ user?: User;
31
+ }>;
32
+ export declare function logoutBackend(): Promise<{
33
+ success: boolean;
34
+ }>;