@solvapay/react-supabase 1.0.0-preview.10

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 ADDED
@@ -0,0 +1,103 @@
1
+ # @solvapay/react-supabase
2
+
3
+ Supabase authentication adapter for SolvaPay React Provider.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @solvapay/react-supabase @supabase/supabase-js
9
+ # or
10
+ pnpm add @solvapay/react-supabase @supabase/supabase-js
11
+ # or
12
+ yarn add @solvapay/react-supabase @supabase/supabase-js
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ Use the Supabase adapter with `SolvaPayProvider`:
18
+
19
+ ```tsx
20
+ import { SolvaPayProvider } from '@solvapay/react';
21
+ import { createSupabaseAuthAdapter } from '@solvapay/react-supabase';
22
+
23
+ const adapter = createSupabaseAuthAdapter({
24
+ supabaseUrl: process.env.NEXT_PUBLIC_SUPABASE_URL!,
25
+ supabaseAnonKey: process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
26
+ });
27
+
28
+ export default function RootLayout({ children }) {
29
+ return (
30
+ <SolvaPayProvider config={{ auth: { adapter } }}>
31
+ {children}
32
+ </SolvaPayProvider>
33
+ );
34
+ }
35
+ ```
36
+
37
+ ## API
38
+
39
+ ### `createSupabaseAuthAdapter(config)`
40
+
41
+ Creates a Supabase auth adapter instance.
42
+
43
+ **Parameters:**
44
+ - `config.supabaseUrl` (string, required) - Your Supabase project URL
45
+ - `config.supabaseAnonKey` (string, required) - Your Supabase anonymous/public key
46
+
47
+ **Returns:** `AuthAdapter` instance
48
+
49
+ ## How It Works
50
+
51
+ The adapter:
52
+ 1. Creates a Supabase client using your credentials
53
+ 2. Gets the current session using `supabase.auth.getSession()`
54
+ 3. Extracts the access token and user ID from the session
55
+ 4. Returns `null` if no session is available (unauthenticated)
56
+
57
+ The adapter handles errors gracefully and never throws - it returns `null` when authentication is not available.
58
+
59
+ ## Example: Full Setup
60
+
61
+ ```tsx
62
+ 'use client';
63
+
64
+ import { SolvaPayProvider } from '@solvapay/react';
65
+ import { createSupabaseAuthAdapter } from '@solvapay/react-supabase';
66
+
67
+ export default function RootLayout({ children }) {
68
+ const adapter = createSupabaseAuthAdapter({
69
+ supabaseUrl: process.env.NEXT_PUBLIC_SUPABASE_URL!,
70
+ supabaseAnonKey: process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
71
+ });
72
+
73
+ return (
74
+ <html>
75
+ <body>
76
+ <SolvaPayProvider config={{ auth: { adapter } }}>
77
+ {children}
78
+ </SolvaPayProvider>
79
+ </body>
80
+ </html>
81
+ );
82
+ }
83
+ ```
84
+
85
+ ## Custom Adapters
86
+
87
+ You can also create custom adapters for other auth providers. See the `AuthAdapter` interface in `@solvapay/react` for the contract.
88
+
89
+ ```tsx
90
+ import type { AuthAdapter } from '@solvapay/react';
91
+
92
+ const myAuthAdapter: AuthAdapter = {
93
+ async getToken() {
94
+ return await myAuthService.getToken();
95
+ },
96
+ async getUserId() {
97
+ return await myAuthService.getUserId();
98
+ },
99
+ };
100
+
101
+ <SolvaPayProvider config={{ auth: { adapter: myAuthAdapter } }}>
102
+ ```
103
+
package/dist/index.cjs ADDED
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ createSupabaseAuthAdapter: () => createSupabaseAuthAdapter
34
+ });
35
+ module.exports = __toCommonJS(index_exports);
36
+
37
+ // src/supabase-adapter.ts
38
+ function createSupabaseAuthAdapter(config) {
39
+ if (!config.supabaseUrl || !config.supabaseAnonKey) {
40
+ throw new Error(
41
+ "SupabaseAuthAdapter requires both supabaseUrl and supabaseAnonKey"
42
+ );
43
+ }
44
+ let supabaseClient = null;
45
+ let clientPromise = null;
46
+ const getSupabaseClient = async () => {
47
+ if (supabaseClient) {
48
+ return supabaseClient;
49
+ }
50
+ if (clientPromise) {
51
+ return clientPromise;
52
+ }
53
+ clientPromise = (async () => {
54
+ try {
55
+ const { createClient } = await import("@supabase/supabase-js");
56
+ supabaseClient = createClient(config.supabaseUrl, config.supabaseAnonKey);
57
+ return supabaseClient;
58
+ } catch (error) {
59
+ clientPromise = null;
60
+ throw new Error(
61
+ "Failed to load @supabase/supabase-js. Make sure it is installed: npm install @supabase/supabase-js"
62
+ );
63
+ }
64
+ })();
65
+ return clientPromise;
66
+ };
67
+ return {
68
+ async getToken() {
69
+ if (typeof window === "undefined") return null;
70
+ try {
71
+ const supabase = await getSupabaseClient();
72
+ const { data: { session } } = await supabase.auth.getSession();
73
+ return session?.access_token || null;
74
+ } catch (error) {
75
+ console.warn("[SupabaseAuthAdapter] Failed to get token:", error);
76
+ return null;
77
+ }
78
+ },
79
+ async getUserId() {
80
+ if (typeof window === "undefined") return null;
81
+ try {
82
+ const supabase = await getSupabaseClient();
83
+ const { data: { session } } = await supabase.auth.getSession();
84
+ return session?.user?.id || null;
85
+ } catch (error) {
86
+ console.warn("[SupabaseAuthAdapter] Failed to get user ID:", error);
87
+ return null;
88
+ }
89
+ }
90
+ };
91
+ }
92
+ // Annotate the CommonJS export names for ESM import in node:
93
+ 0 && (module.exports = {
94
+ createSupabaseAuthAdapter
95
+ });
@@ -0,0 +1,47 @@
1
+ import { AuthAdapter } from '@solvapay/react';
2
+
3
+ /**
4
+ * Supabase Auth Adapter for SolvaPay React
5
+ *
6
+ * Provides Supabase-specific authentication adapter for use with SolvaPayProvider.
7
+ * This adapter integrates with Supabase Auth to get tokens and user IDs.
8
+ */
9
+
10
+ interface SupabaseAuthAdapterConfig {
11
+ /**
12
+ * Supabase project URL
13
+ */
14
+ supabaseUrl: string;
15
+ /**
16
+ * Supabase anonymous/public key
17
+ */
18
+ supabaseAnonKey: string;
19
+ }
20
+ /**
21
+ * Create a Supabase auth adapter for SolvaPayProvider
22
+ *
23
+ * This adapter uses Supabase's client-side auth to get tokens and user IDs.
24
+ * It dynamically imports @supabase/supabase-js to avoid adding it as a dependency
25
+ * if Supabase isn't being used.
26
+ *
27
+ * @param config - Supabase configuration
28
+ * @returns AuthAdapter instance
29
+ *
30
+ * @example
31
+ * ```tsx
32
+ * import { createSupabaseAuthAdapter } from '@solvapay/react-supabase';
33
+ * import { SolvaPayProvider } from '@solvapay/react';
34
+ *
35
+ * const adapter = createSupabaseAuthAdapter({
36
+ * supabaseUrl: process.env.NEXT_PUBLIC_SUPABASE_URL!,
37
+ * supabaseAnonKey: process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
38
+ * });
39
+ *
40
+ * <SolvaPayProvider config={{ auth: { adapter } }}>
41
+ * {children}
42
+ * </SolvaPayProvider>
43
+ * ```
44
+ */
45
+ declare function createSupabaseAuthAdapter(config: SupabaseAuthAdapterConfig): AuthAdapter;
46
+
47
+ export { type SupabaseAuthAdapterConfig, createSupabaseAuthAdapter };
@@ -0,0 +1,47 @@
1
+ import { AuthAdapter } from '@solvapay/react';
2
+
3
+ /**
4
+ * Supabase Auth Adapter for SolvaPay React
5
+ *
6
+ * Provides Supabase-specific authentication adapter for use with SolvaPayProvider.
7
+ * This adapter integrates with Supabase Auth to get tokens and user IDs.
8
+ */
9
+
10
+ interface SupabaseAuthAdapterConfig {
11
+ /**
12
+ * Supabase project URL
13
+ */
14
+ supabaseUrl: string;
15
+ /**
16
+ * Supabase anonymous/public key
17
+ */
18
+ supabaseAnonKey: string;
19
+ }
20
+ /**
21
+ * Create a Supabase auth adapter for SolvaPayProvider
22
+ *
23
+ * This adapter uses Supabase's client-side auth to get tokens and user IDs.
24
+ * It dynamically imports @supabase/supabase-js to avoid adding it as a dependency
25
+ * if Supabase isn't being used.
26
+ *
27
+ * @param config - Supabase configuration
28
+ * @returns AuthAdapter instance
29
+ *
30
+ * @example
31
+ * ```tsx
32
+ * import { createSupabaseAuthAdapter } from '@solvapay/react-supabase';
33
+ * import { SolvaPayProvider } from '@solvapay/react';
34
+ *
35
+ * const adapter = createSupabaseAuthAdapter({
36
+ * supabaseUrl: process.env.NEXT_PUBLIC_SUPABASE_URL!,
37
+ * supabaseAnonKey: process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
38
+ * });
39
+ *
40
+ * <SolvaPayProvider config={{ auth: { adapter } }}>
41
+ * {children}
42
+ * </SolvaPayProvider>
43
+ * ```
44
+ */
45
+ declare function createSupabaseAuthAdapter(config: SupabaseAuthAdapterConfig): AuthAdapter;
46
+
47
+ export { type SupabaseAuthAdapterConfig, createSupabaseAuthAdapter };
package/dist/index.js ADDED
@@ -0,0 +1,58 @@
1
+ // src/supabase-adapter.ts
2
+ function createSupabaseAuthAdapter(config) {
3
+ if (!config.supabaseUrl || !config.supabaseAnonKey) {
4
+ throw new Error(
5
+ "SupabaseAuthAdapter requires both supabaseUrl and supabaseAnonKey"
6
+ );
7
+ }
8
+ let supabaseClient = null;
9
+ let clientPromise = null;
10
+ const getSupabaseClient = async () => {
11
+ if (supabaseClient) {
12
+ return supabaseClient;
13
+ }
14
+ if (clientPromise) {
15
+ return clientPromise;
16
+ }
17
+ clientPromise = (async () => {
18
+ try {
19
+ const { createClient } = await import("@supabase/supabase-js");
20
+ supabaseClient = createClient(config.supabaseUrl, config.supabaseAnonKey);
21
+ return supabaseClient;
22
+ } catch (error) {
23
+ clientPromise = null;
24
+ throw new Error(
25
+ "Failed to load @supabase/supabase-js. Make sure it is installed: npm install @supabase/supabase-js"
26
+ );
27
+ }
28
+ })();
29
+ return clientPromise;
30
+ };
31
+ return {
32
+ async getToken() {
33
+ if (typeof window === "undefined") return null;
34
+ try {
35
+ const supabase = await getSupabaseClient();
36
+ const { data: { session } } = await supabase.auth.getSession();
37
+ return session?.access_token || null;
38
+ } catch (error) {
39
+ console.warn("[SupabaseAuthAdapter] Failed to get token:", error);
40
+ return null;
41
+ }
42
+ },
43
+ async getUserId() {
44
+ if (typeof window === "undefined") return null;
45
+ try {
46
+ const supabase = await getSupabaseClient();
47
+ const { data: { session } } = await supabase.auth.getSession();
48
+ return session?.user?.id || null;
49
+ } catch (error) {
50
+ console.warn("[SupabaseAuthAdapter] Failed to get user ID:", error);
51
+ return null;
52
+ }
53
+ }
54
+ };
55
+ }
56
+ export {
57
+ createSupabaseAuthAdapter
58
+ };
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "@solvapay/react-supabase",
3
+ "version": "1.0.0-preview.10",
4
+ "type": "module",
5
+ "main": "./dist/index.cjs",
6
+ "module": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "files": [
9
+ "dist",
10
+ "README.md"
11
+ ],
12
+ "publishConfig": {
13
+ "access": "public"
14
+ },
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "https://github.com/solvapay/solvapay-sdk.git",
18
+ "directory": "packages/react-supabase"
19
+ },
20
+ "peerDependencies": {
21
+ "@solvapay/react": "^1.0.0-preview.9",
22
+ "@supabase/supabase-js": "^2.0.0"
23
+ },
24
+ "devDependencies": {
25
+ "@types/react": "^18.2.74",
26
+ "typescript": "^5.5.4",
27
+ "tsup": "^8.0.0",
28
+ "vitest": "^2.0.5",
29
+ "@solvapay/react": "1.0.0-preview.10"
30
+ },
31
+ "scripts": {
32
+ "build": "tsup src/index.ts --format esm,cjs --dts --tsconfig tsconfig.build.json",
33
+ "test": "vitest run || exit 0",
34
+ "test:unit": "vitest run || exit 0",
35
+ "test:watch": "vitest"
36
+ }
37
+ }