@solvapay/react-supabase 1.0.9 → 1.0.10-preview-cb8ad16e16ce8f8f357bd7f2e7068d85159df587
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 +27 -39
- package/dist/index.cjs +45 -46
- package/dist/index.js +45 -46
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,20 +1,23 @@
|
|
|
1
1
|
# @solvapay/react-supabase
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/@solvapay/react-supabase)
|
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
Supabase authentication adapter for `SolvaPayProvider` — session tokens and user IDs without a second GoTrue instance.
|
|
7
|
+
|
|
8
|
+
**When to use this package:** your React app already uses Supabase Auth and you want `@solvapay/react` checkout to send authenticated requests.
|
|
9
|
+
|
|
10
|
+
## Install
|
|
6
11
|
|
|
7
12
|
```bash
|
|
8
|
-
npm install @solvapay/react-supabase @supabase/supabase-js
|
|
9
|
-
# or
|
|
10
13
|
pnpm add @solvapay/react-supabase @supabase/supabase-js
|
|
11
|
-
# or
|
|
12
|
-
yarn add @solvapay/react-supabase @supabase/supabase-js
|
|
13
14
|
```
|
|
14
15
|
|
|
15
|
-
|
|
16
|
+
Guides: [React](https://docs.solvapay.com/sdks/typescript/guides/react) · [Supabase Edge](https://docs.solvapay.com/sdks/typescript/guides/supabase-edge)
|
|
17
|
+
|
|
18
|
+
## Quickstart
|
|
16
19
|
|
|
17
|
-
Pass your existing Supabase client
|
|
20
|
+
Pass your existing Supabase client:
|
|
18
21
|
|
|
19
22
|
```tsx
|
|
20
23
|
import { createClient } from '@supabase/supabase-js'
|
|
@@ -26,44 +29,29 @@ const supabase = createClient(
|
|
|
26
29
|
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
|
|
27
30
|
)
|
|
28
31
|
|
|
29
|
-
const adapter = createSupabaseAuthAdapter({ client: supabase })
|
|
30
|
-
|
|
31
32
|
export default function RootLayout({ children }) {
|
|
32
|
-
return
|
|
33
|
+
return (
|
|
34
|
+
<SolvaPayProvider config={{ auth: { adapter: createSupabaseAuthAdapter({ client: supabase }) } }}>
|
|
35
|
+
{children}
|
|
36
|
+
</SolvaPayProvider>
|
|
37
|
+
)
|
|
33
38
|
}
|
|
34
39
|
```
|
|
35
40
|
|
|
36
|
-
Reusing the host app's client
|
|
37
|
-
|
|
38
|
-
## API
|
|
41
|
+
Reusing the host app's client is required for `@supabase/ssr`, custom `auth.storageKey`, or `persistSession: false`.
|
|
39
42
|
|
|
40
|
-
|
|
43
|
+
## How it works
|
|
41
44
|
|
|
42
|
-
|
|
45
|
+
Calls `supabase.auth.getSession()` for the current token and user ID. Subscribes to `onAuthStateChange` so `SolvaPayProvider` reacts to sign-in, sign-out, and refresh without polling. Returns `null` when there is no session. Never throws.
|
|
43
46
|
|
|
44
|
-
|
|
47
|
+
## See also
|
|
45
48
|
|
|
46
|
-
|
|
49
|
+
- [`@solvapay/react`](../react) — checkout UI and hooks
|
|
50
|
+
- [`@solvapay/auth`](../auth) — server-side Supabase JWT adapter
|
|
51
|
+
- [`@solvapay/server/fetch`](../server) — Supabase Edge Function handlers
|
|
52
|
+
- [Supabase Edge example](../../examples/supabase-edge)
|
|
47
53
|
|
|
48
|
-
##
|
|
54
|
+
## Support
|
|
49
55
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
## Custom Adapters
|
|
53
|
-
|
|
54
|
-
You can also create custom adapters for other auth providers. See the `AuthAdapter` interface in `@solvapay/react` for the contract.
|
|
55
|
-
|
|
56
|
-
```tsx
|
|
57
|
-
import type { AuthAdapter } from '@solvapay/react';
|
|
58
|
-
|
|
59
|
-
const myAuthAdapter: AuthAdapter = {
|
|
60
|
-
async getToken() {
|
|
61
|
-
return await myAuthService.getToken();
|
|
62
|
-
},
|
|
63
|
-
async getUserId() {
|
|
64
|
-
return await myAuthService.getUserId();
|
|
65
|
-
},
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
<SolvaPayProvider config={{ auth: { adapter: myAuthAdapter } }}>
|
|
69
|
-
```
|
|
56
|
+
- **Issues**: [GitHub Issues](https://github.com/solvapay/solvapay-sdk/issues)
|
|
57
|
+
- **Docs**: [docs.solvapay.com/sdks/typescript/guides/supabase-edge](https://docs.solvapay.com/sdks/typescript/guides/supabase-edge)
|
package/dist/index.cjs
CHANGED
|
@@ -25,6 +25,7 @@ __export(index_exports, {
|
|
|
25
25
|
module.exports = __toCommonJS(index_exports);
|
|
26
26
|
|
|
27
27
|
// src/supabase-adapter.ts
|
|
28
|
+
var import_react = require("@solvapay/react");
|
|
28
29
|
function createSupabaseAuthAdapter(config) {
|
|
29
30
|
if (!config || !config.client) {
|
|
30
31
|
throw new Error(
|
|
@@ -32,54 +33,52 @@ function createSupabaseAuthAdapter(config) {
|
|
|
32
33
|
);
|
|
33
34
|
}
|
|
34
35
|
const client = config.client;
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
return null;
|
|
46
|
-
}
|
|
47
|
-
},
|
|
48
|
-
async getUserId() {
|
|
49
|
-
if (typeof window === "undefined") return null;
|
|
50
|
-
try {
|
|
51
|
-
const {
|
|
52
|
-
data: { session }
|
|
53
|
-
} = await client.auth.getSession();
|
|
54
|
-
return session?.user?.id || null;
|
|
55
|
-
} catch (error) {
|
|
56
|
-
console.warn("[SupabaseAuthAdapter] Failed to get user ID:", error);
|
|
57
|
-
return null;
|
|
58
|
-
}
|
|
59
|
-
},
|
|
60
|
-
subscribe(listener) {
|
|
61
|
-
if (typeof window === "undefined") {
|
|
62
|
-
return () => void 0;
|
|
63
|
-
}
|
|
64
|
-
try {
|
|
65
|
-
const {
|
|
66
|
-
data: { subscription }
|
|
67
|
-
} = client.auth.onAuthStateChange(() => {
|
|
68
|
-
listener();
|
|
69
|
-
});
|
|
70
|
-
return () => {
|
|
71
|
-
try {
|
|
72
|
-
subscription.unsubscribe();
|
|
73
|
-
} catch (error) {
|
|
74
|
-
console.warn("[SupabaseAuthAdapter] Failed to unsubscribe:", error);
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
} catch (error) {
|
|
78
|
-
console.warn("[SupabaseAuthAdapter] Failed to subscribe to auth changes:", error);
|
|
79
|
-
return () => void 0;
|
|
80
|
-
}
|
|
36
|
+
const readSession = async () => {
|
|
37
|
+
if (typeof window === "undefined") return null;
|
|
38
|
+
try {
|
|
39
|
+
const {
|
|
40
|
+
data: { session }
|
|
41
|
+
} = await client.auth.getSession();
|
|
42
|
+
return session;
|
|
43
|
+
} catch (error) {
|
|
44
|
+
console.warn("[SupabaseAuthAdapter] Failed to read session:", error);
|
|
45
|
+
return null;
|
|
81
46
|
}
|
|
82
47
|
};
|
|
48
|
+
const subscribe = (listener) => {
|
|
49
|
+
if (typeof window === "undefined") {
|
|
50
|
+
return () => void 0;
|
|
51
|
+
}
|
|
52
|
+
try {
|
|
53
|
+
const {
|
|
54
|
+
data: { subscription }
|
|
55
|
+
} = client.auth.onAuthStateChange(() => {
|
|
56
|
+
listener();
|
|
57
|
+
});
|
|
58
|
+
return () => {
|
|
59
|
+
try {
|
|
60
|
+
subscription.unsubscribe();
|
|
61
|
+
} catch (error) {
|
|
62
|
+
console.warn("[SupabaseAuthAdapter] Failed to unsubscribe:", error);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
} catch (error) {
|
|
66
|
+
console.warn("[SupabaseAuthAdapter] Failed to subscribe to auth changes:", error);
|
|
67
|
+
return () => void 0;
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
return (0, import_react.createSessionAuthAdapter)({
|
|
71
|
+
getToken: async () => {
|
|
72
|
+
const session = await readSession();
|
|
73
|
+
return session?.access_token || null;
|
|
74
|
+
},
|
|
75
|
+
getUserId: async () => {
|
|
76
|
+
const session = await readSession();
|
|
77
|
+
return session?.user?.id || null;
|
|
78
|
+
},
|
|
79
|
+
subscribe,
|
|
80
|
+
sentinelToken: "supabase-session"
|
|
81
|
+
});
|
|
83
82
|
}
|
|
84
83
|
// Annotate the CommonJS export names for ESM import in node:
|
|
85
84
|
0 && (module.exports = {
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// src/supabase-adapter.ts
|
|
2
|
+
import { createSessionAuthAdapter } from "@solvapay/react";
|
|
2
3
|
function createSupabaseAuthAdapter(config) {
|
|
3
4
|
if (!config || !config.client) {
|
|
4
5
|
throw new Error(
|
|
@@ -6,54 +7,52 @@ function createSupabaseAuthAdapter(config) {
|
|
|
6
7
|
);
|
|
7
8
|
}
|
|
8
9
|
const client = config.client;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
return null;
|
|
20
|
-
}
|
|
21
|
-
},
|
|
22
|
-
async getUserId() {
|
|
23
|
-
if (typeof window === "undefined") return null;
|
|
24
|
-
try {
|
|
25
|
-
const {
|
|
26
|
-
data: { session }
|
|
27
|
-
} = await client.auth.getSession();
|
|
28
|
-
return session?.user?.id || null;
|
|
29
|
-
} catch (error) {
|
|
30
|
-
console.warn("[SupabaseAuthAdapter] Failed to get user ID:", error);
|
|
31
|
-
return null;
|
|
32
|
-
}
|
|
33
|
-
},
|
|
34
|
-
subscribe(listener) {
|
|
35
|
-
if (typeof window === "undefined") {
|
|
36
|
-
return () => void 0;
|
|
37
|
-
}
|
|
38
|
-
try {
|
|
39
|
-
const {
|
|
40
|
-
data: { subscription }
|
|
41
|
-
} = client.auth.onAuthStateChange(() => {
|
|
42
|
-
listener();
|
|
43
|
-
});
|
|
44
|
-
return () => {
|
|
45
|
-
try {
|
|
46
|
-
subscription.unsubscribe();
|
|
47
|
-
} catch (error) {
|
|
48
|
-
console.warn("[SupabaseAuthAdapter] Failed to unsubscribe:", error);
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
} catch (error) {
|
|
52
|
-
console.warn("[SupabaseAuthAdapter] Failed to subscribe to auth changes:", error);
|
|
53
|
-
return () => void 0;
|
|
54
|
-
}
|
|
10
|
+
const readSession = async () => {
|
|
11
|
+
if (typeof window === "undefined") return null;
|
|
12
|
+
try {
|
|
13
|
+
const {
|
|
14
|
+
data: { session }
|
|
15
|
+
} = await client.auth.getSession();
|
|
16
|
+
return session;
|
|
17
|
+
} catch (error) {
|
|
18
|
+
console.warn("[SupabaseAuthAdapter] Failed to read session:", error);
|
|
19
|
+
return null;
|
|
55
20
|
}
|
|
56
21
|
};
|
|
22
|
+
const subscribe = (listener) => {
|
|
23
|
+
if (typeof window === "undefined") {
|
|
24
|
+
return () => void 0;
|
|
25
|
+
}
|
|
26
|
+
try {
|
|
27
|
+
const {
|
|
28
|
+
data: { subscription }
|
|
29
|
+
} = client.auth.onAuthStateChange(() => {
|
|
30
|
+
listener();
|
|
31
|
+
});
|
|
32
|
+
return () => {
|
|
33
|
+
try {
|
|
34
|
+
subscription.unsubscribe();
|
|
35
|
+
} catch (error) {
|
|
36
|
+
console.warn("[SupabaseAuthAdapter] Failed to unsubscribe:", error);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
} catch (error) {
|
|
40
|
+
console.warn("[SupabaseAuthAdapter] Failed to subscribe to auth changes:", error);
|
|
41
|
+
return () => void 0;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
return createSessionAuthAdapter({
|
|
45
|
+
getToken: async () => {
|
|
46
|
+
const session = await readSession();
|
|
47
|
+
return session?.access_token || null;
|
|
48
|
+
},
|
|
49
|
+
getUserId: async () => {
|
|
50
|
+
const session = await readSession();
|
|
51
|
+
return session?.user?.id || null;
|
|
52
|
+
},
|
|
53
|
+
subscribe,
|
|
54
|
+
sentinelToken: "supabase-session"
|
|
55
|
+
});
|
|
57
56
|
}
|
|
58
57
|
export {
|
|
59
58
|
createSupabaseAuthAdapter
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@solvapay/react-supabase",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.10-preview-cb8ad16e16ce8f8f357bd7f2e7068d85159df587",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -19,14 +19,14 @@
|
|
|
19
19
|
},
|
|
20
20
|
"peerDependencies": {
|
|
21
21
|
"@supabase/supabase-js": "^2.0.0",
|
|
22
|
-
"@solvapay/react": "^1.
|
|
22
|
+
"@solvapay/react": "^1.3.0-preview-cb8ad16e16ce8f8f357bd7f2e7068d85159df587"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@types/react": "^19.2.14",
|
|
26
26
|
"tsup": "^8.5.1",
|
|
27
27
|
"typescript": "^5.9.3",
|
|
28
28
|
"vitest": "^4.1.2",
|
|
29
|
-
"@solvapay/react": "1.
|
|
29
|
+
"@solvapay/react": "1.3.0-preview-cb8ad16e16ce8f8f357bd7f2e7068d85159df587"
|
|
30
30
|
},
|
|
31
31
|
"scripts": {
|
|
32
32
|
"build": "tsup src/index.ts --format esm,cjs --dts --tsconfig tsconfig.build.json",
|