@supabase/server 0.1.1-rc.24 → 0.1.1-rc.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapters/hono/index.cjs +27 -1
- package/dist/adapters/hono/index.d.cts +27 -1
- package/dist/adapters/hono/index.d.mts +27 -1
- package/dist/adapters/hono/index.mjs +27 -1
- package/dist/core/index.cjs +1 -1
- package/dist/core/index.d.cts +2 -2
- package/dist/core/index.d.mts +2 -2
- package/dist/core/index.mjs +1 -1
- package/dist/create-admin-client-Cp7FxI6O.d.cts +271 -0
- package/dist/create-admin-client-ZTnl1zMe.d.mts +271 -0
- package/dist/{create-supabase-context-BrSIe29v.mjs → create-supabase-context-CmWaH3s6.mjs} +21 -1
- package/dist/{create-supabase-context-DNWor6i_.cjs → create-supabase-context-DcVorGKG.cjs} +21 -1
- package/dist/index.cjs +45 -2
- package/dist/index.d.cts +45 -2
- package/dist/index.d.mts +45 -2
- package/dist/index.mjs +45 -2
- package/dist/types-ClmJ8pi8.d.mts +227 -0
- package/dist/types-CnKoFCMX.d.cts +227 -0
- package/dist/{verify-auth-DxUT0XoT.mjs → verify-auth-2S7zFfR-.mjs} +217 -0
- package/dist/{verify-auth-6a1UPrFz.cjs → verify-auth-DvRVnjdq.cjs} +217 -0
- package/dist/wrappers/index.cjs +19 -0
- package/dist/wrappers/index.d.cts +19 -0
- package/dist/wrappers/index.d.mts +19 -0
- package/dist/wrappers/index.mjs +19 -0
- package/package.json +1 -1
- package/dist/create-admin-client-BQEHqeFW.d.mts +0 -60
- package/dist/create-admin-client-CnuiHPpV.d.cts +0 -60
- package/dist/types-C9J9JcPD.d.cts +0 -59
- package/dist/types-Ceetds5F.d.mts +0 -59
|
@@ -1,9 +1,35 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_create_supabase_context = require('../../create-supabase-context-
|
|
2
|
+
const require_create_supabase_context = require('../../create-supabase-context-DcVorGKG.cjs');
|
|
3
3
|
let hono_http_exception = require("hono/http-exception");
|
|
4
4
|
let hono_factory = require("hono/factory");
|
|
5
5
|
|
|
6
6
|
//#region src/adapters/hono/middleware.ts
|
|
7
|
+
/**
|
|
8
|
+
* Hono middleware that creates a {@link SupabaseContext} and stores it in `c.var.supabaseContext`.
|
|
9
|
+
*
|
|
10
|
+
* Skips if a previous middleware already set the context, enabling route-level overrides.
|
|
11
|
+
* Throws a Hono `HTTPException` on auth failure.
|
|
12
|
+
*
|
|
13
|
+
* @param config - Auth modes and optional environment overrides. CORS is excluded — use Hono's `cors()`.
|
|
14
|
+
* @returns A Hono middleware that sets `c.var.supabaseContext`.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* import { Hono } from 'hono'
|
|
19
|
+
* import { withSupabase } from '@supabase/server/adapters/hono'
|
|
20
|
+
*
|
|
21
|
+
* const app = new Hono()
|
|
22
|
+
* app.use('*', withSupabase({ allow: 'user' }))
|
|
23
|
+
*
|
|
24
|
+
* app.get('/profile', async (c) => {
|
|
25
|
+
* const { supabase } = c.var.supabaseContext
|
|
26
|
+
* const { data } = await supabase.rpc('get_profile')
|
|
27
|
+
* return c.json(data)
|
|
28
|
+
* })
|
|
29
|
+
*
|
|
30
|
+
* export default { fetch: app.fetch }
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
7
33
|
function withSupabase(config) {
|
|
8
34
|
return (0, hono_factory.createMiddleware)(async (c, next) => {
|
|
9
35
|
if (c.var.supabaseContext) {
|
|
@@ -1,7 +1,33 @@
|
|
|
1
|
-
import { l as WithSupabaseConfig, o as SupabaseContext } from "../../types-
|
|
1
|
+
import { l as WithSupabaseConfig, o as SupabaseContext } from "../../types-CnKoFCMX.cjs";
|
|
2
2
|
import * as hono_types0 from "hono/types";
|
|
3
3
|
|
|
4
4
|
//#region src/adapters/hono/middleware.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Hono middleware that creates a {@link SupabaseContext} and stores it in `c.var.supabaseContext`.
|
|
7
|
+
*
|
|
8
|
+
* Skips if a previous middleware already set the context, enabling route-level overrides.
|
|
9
|
+
* Throws a Hono `HTTPException` on auth failure.
|
|
10
|
+
*
|
|
11
|
+
* @param config - Auth modes and optional environment overrides. CORS is excluded — use Hono's `cors()`.
|
|
12
|
+
* @returns A Hono middleware that sets `c.var.supabaseContext`.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* import { Hono } from 'hono'
|
|
17
|
+
* import { withSupabase } from '@supabase/server/adapters/hono'
|
|
18
|
+
*
|
|
19
|
+
* const app = new Hono()
|
|
20
|
+
* app.use('*', withSupabase({ allow: 'user' }))
|
|
21
|
+
*
|
|
22
|
+
* app.get('/profile', async (c) => {
|
|
23
|
+
* const { supabase } = c.var.supabaseContext
|
|
24
|
+
* const { data } = await supabase.rpc('get_profile')
|
|
25
|
+
* return c.json(data)
|
|
26
|
+
* })
|
|
27
|
+
*
|
|
28
|
+
* export default { fetch: app.fetch }
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
5
31
|
declare function withSupabase(config?: Omit<WithSupabaseConfig, 'cors'>): hono_types0.MiddlewareHandler<{
|
|
6
32
|
Variables: {
|
|
7
33
|
supabaseContext: SupabaseContext;
|
|
@@ -1,7 +1,33 @@
|
|
|
1
|
-
import { l as WithSupabaseConfig, o as SupabaseContext } from "../../types-
|
|
1
|
+
import { l as WithSupabaseConfig, o as SupabaseContext } from "../../types-ClmJ8pi8.mjs";
|
|
2
2
|
import * as hono_types0 from "hono/types";
|
|
3
3
|
|
|
4
4
|
//#region src/adapters/hono/middleware.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Hono middleware that creates a {@link SupabaseContext} and stores it in `c.var.supabaseContext`.
|
|
7
|
+
*
|
|
8
|
+
* Skips if a previous middleware already set the context, enabling route-level overrides.
|
|
9
|
+
* Throws a Hono `HTTPException` on auth failure.
|
|
10
|
+
*
|
|
11
|
+
* @param config - Auth modes and optional environment overrides. CORS is excluded — use Hono's `cors()`.
|
|
12
|
+
* @returns A Hono middleware that sets `c.var.supabaseContext`.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* import { Hono } from 'hono'
|
|
17
|
+
* import { withSupabase } from '@supabase/server/adapters/hono'
|
|
18
|
+
*
|
|
19
|
+
* const app = new Hono()
|
|
20
|
+
* app.use('*', withSupabase({ allow: 'user' }))
|
|
21
|
+
*
|
|
22
|
+
* app.get('/profile', async (c) => {
|
|
23
|
+
* const { supabase } = c.var.supabaseContext
|
|
24
|
+
* const { data } = await supabase.rpc('get_profile')
|
|
25
|
+
* return c.json(data)
|
|
26
|
+
* })
|
|
27
|
+
*
|
|
28
|
+
* export default { fetch: app.fetch }
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
5
31
|
declare function withSupabase(config?: Omit<WithSupabaseConfig, 'cors'>): hono_types0.MiddlewareHandler<{
|
|
6
32
|
Variables: {
|
|
7
33
|
supabaseContext: SupabaseContext;
|
|
@@ -1,8 +1,34 @@
|
|
|
1
|
-
import { t as createSupabaseContext } from "../../create-supabase-context-
|
|
1
|
+
import { t as createSupabaseContext } from "../../create-supabase-context-CmWaH3s6.mjs";
|
|
2
2
|
import { HTTPException } from "hono/http-exception";
|
|
3
3
|
import { createMiddleware } from "hono/factory";
|
|
4
4
|
|
|
5
5
|
//#region src/adapters/hono/middleware.ts
|
|
6
|
+
/**
|
|
7
|
+
* Hono middleware that creates a {@link SupabaseContext} and stores it in `c.var.supabaseContext`.
|
|
8
|
+
*
|
|
9
|
+
* Skips if a previous middleware already set the context, enabling route-level overrides.
|
|
10
|
+
* Throws a Hono `HTTPException` on auth failure.
|
|
11
|
+
*
|
|
12
|
+
* @param config - Auth modes and optional environment overrides. CORS is excluded — use Hono's `cors()`.
|
|
13
|
+
* @returns A Hono middleware that sets `c.var.supabaseContext`.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* import { Hono } from 'hono'
|
|
18
|
+
* import { withSupabase } from '@supabase/server/adapters/hono'
|
|
19
|
+
*
|
|
20
|
+
* const app = new Hono()
|
|
21
|
+
* app.use('*', withSupabase({ allow: 'user' }))
|
|
22
|
+
*
|
|
23
|
+
* app.get('/profile', async (c) => {
|
|
24
|
+
* const { supabase } = c.var.supabaseContext
|
|
25
|
+
* const { data } = await supabase.rpc('get_profile')
|
|
26
|
+
* return c.json(data)
|
|
27
|
+
* })
|
|
28
|
+
*
|
|
29
|
+
* export default { fetch: app.fetch }
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
6
32
|
function withSupabase(config) {
|
|
7
33
|
return createMiddleware(async (c, next) => {
|
|
8
34
|
if (c.var.supabaseContext) {
|
package/dist/core/index.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_verify_auth = require('../verify-auth-
|
|
2
|
+
const require_verify_auth = require('../verify-auth-DvRVnjdq.cjs');
|
|
3
3
|
|
|
4
4
|
exports.createAdminClient = require_verify_auth.createAdminClient;
|
|
5
5
|
exports.createContextClient = require_verify_auth.createContextClient;
|
package/dist/core/index.d.cts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import "../types-
|
|
2
|
-
import { a as extractCredentials, i as verifyCredentials, n as createContextClient, o as resolveEnv, r as verifyAuth, t as createAdminClient } from "../create-admin-client-
|
|
1
|
+
import "../types-CnKoFCMX.cjs";
|
|
2
|
+
import { a as extractCredentials, i as verifyCredentials, n as createContextClient, o as resolveEnv, r as verifyAuth, t as createAdminClient } from "../create-admin-client-Cp7FxI6O.cjs";
|
|
3
3
|
export { createAdminClient, createContextClient, extractCredentials, resolveEnv, verifyAuth, verifyCredentials };
|
package/dist/core/index.d.mts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import "../types-
|
|
2
|
-
import { a as extractCredentials, i as verifyCredentials, n as createContextClient, o as resolveEnv, r as verifyAuth, t as createAdminClient } from "../create-admin-client-
|
|
1
|
+
import "../types-ClmJ8pi8.mjs";
|
|
2
|
+
import { a as extractCredentials, i as verifyCredentials, n as createContextClient, o as resolveEnv, r as verifyAuth, t as createAdminClient } from "../create-admin-client-ZTnl1zMe.mjs";
|
|
3
3
|
export { createAdminClient, createContextClient, extractCredentials, resolveEnv, verifyAuth, verifyCredentials };
|
package/dist/core/index.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { a as createAdminClient, i as createContextClient, n as verifyCredentials, o as resolveEnv, r as extractCredentials, t as verifyAuth } from "../verify-auth-
|
|
1
|
+
import { a as createAdminClient, i as createContextClient, n as verifyCredentials, o as resolveEnv, r as extractCredentials, t as verifyAuth } from "../verify-auth-2S7zFfR-.mjs";
|
|
2
2
|
|
|
3
3
|
export { createAdminClient, createContextClient, extractCredentials, resolveEnv, verifyAuth, verifyCredentials };
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
import { i as Credentials, n as AllowWithKey, r as AuthResult, s as SupabaseEnv } from "./types-CnKoFCMX.cjs";
|
|
2
|
+
import { SupabaseClient } from "@supabase/supabase-js";
|
|
3
|
+
|
|
4
|
+
//#region src/errors.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Thrown when a required environment variable is missing or malformed.
|
|
7
|
+
*
|
|
8
|
+
* Has a fixed `status` of `500` since environment errors are server-side
|
|
9
|
+
* configuration issues, not client errors.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* import { EnvError } from '@supabase/server'
|
|
14
|
+
*
|
|
15
|
+
* try {
|
|
16
|
+
* const client = createAdminClient()
|
|
17
|
+
* } catch (e) {
|
|
18
|
+
* if (e instanceof EnvError) {
|
|
19
|
+
* console.error(`Config issue [${e.code}]: ${e.message}`)
|
|
20
|
+
* // → "Config issue [MISSING_SUPABASE_URL]: SUPABASE_URL is required but not set"
|
|
21
|
+
* }
|
|
22
|
+
* }
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
declare class EnvError extends Error {
|
|
26
|
+
/** Always `500` — environment errors are server-side issues. */
|
|
27
|
+
readonly status = 500;
|
|
28
|
+
/**
|
|
29
|
+
* Machine-readable error code.
|
|
30
|
+
*
|
|
31
|
+
* Known codes:
|
|
32
|
+
* - `"MISSING_SUPABASE_URL"` — `SUPABASE_URL` not set
|
|
33
|
+
* - `"MISSING_PUBLISHABLE_KEY"` — No publishable key found
|
|
34
|
+
* - `"MISSING_SECRET_KEY"` — No secret key found
|
|
35
|
+
* - `"ENV_ERROR"` — Generic environment error
|
|
36
|
+
*/
|
|
37
|
+
readonly code: string;
|
|
38
|
+
constructor(message: string, code?: string);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Thrown when authentication or authorization fails.
|
|
42
|
+
*
|
|
43
|
+
* Carries an HTTP `status` code suitable for returning directly in a response
|
|
44
|
+
* (typically `401` for invalid credentials, `500` for server-side auth failures).
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```ts
|
|
48
|
+
* import { AuthError, createSupabaseContext } from '@supabase/server'
|
|
49
|
+
*
|
|
50
|
+
* const { data: ctx, error } = await createSupabaseContext(request, { allow: 'user' })
|
|
51
|
+
* if (error) {
|
|
52
|
+
* // error is an AuthError
|
|
53
|
+
* return Response.json(
|
|
54
|
+
* { error: error.message, code: error.code },
|
|
55
|
+
* { status: error.status },
|
|
56
|
+
* )
|
|
57
|
+
* }
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
declare class AuthError extends Error {
|
|
61
|
+
/**
|
|
62
|
+
* HTTP status code.
|
|
63
|
+
*
|
|
64
|
+
* - `401` — Invalid or missing credentials
|
|
65
|
+
* - `500` — Server-side auth failure (e.g., missing JWKS, env misconfiguration)
|
|
66
|
+
*/
|
|
67
|
+
readonly status: number;
|
|
68
|
+
/**
|
|
69
|
+
* Machine-readable error code.
|
|
70
|
+
*
|
|
71
|
+
* Known codes:
|
|
72
|
+
* - `"INVALID_CREDENTIALS"` — No credential matched any allowed auth mode
|
|
73
|
+
* - `"CLIENT_ERROR"` — Failed to create a Supabase client after auth succeeded
|
|
74
|
+
* - `"AUTH_ERROR"` — Generic authentication error
|
|
75
|
+
* - Any `EnvError` code (propagated when env resolution fails during auth)
|
|
76
|
+
*/
|
|
77
|
+
readonly code: string;
|
|
78
|
+
constructor(message: string, code?: string, status?: number);
|
|
79
|
+
}
|
|
80
|
+
//#endregion
|
|
81
|
+
//#region src/core/resolve-env.d.ts
|
|
82
|
+
/**
|
|
83
|
+
* Resolves Supabase environment configuration from runtime environment variables.
|
|
84
|
+
*
|
|
85
|
+
* Reads `SUPABASE_URL`, keys (`SUPABASE_PUBLISHABLE_KEYS` / `SUPABASE_SECRET_KEYS`),
|
|
86
|
+
* and `SUPABASE_JWKS`. Works across Deno, Node.js, and Bun. For Cloudflare Workers,
|
|
87
|
+
* use `overrides` or enable node-compat.
|
|
88
|
+
*
|
|
89
|
+
* @param overrides - Partial values that take precedence over env vars.
|
|
90
|
+
* @returns `{ data: SupabaseEnv, error: null }` on success, `{ data: null, error: EnvError }` on failure.
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* ```ts
|
|
94
|
+
* const { data: env, error } = resolveEnv()
|
|
95
|
+
* if (error) throw error
|
|
96
|
+
*
|
|
97
|
+
* // Override for tests
|
|
98
|
+
* const { data: env } = resolveEnv({ url: 'http://localhost:54321' })
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
declare function resolveEnv(overrides?: Partial<SupabaseEnv>): {
|
|
102
|
+
data: SupabaseEnv;
|
|
103
|
+
error: null;
|
|
104
|
+
} | {
|
|
105
|
+
data: null;
|
|
106
|
+
error: EnvError;
|
|
107
|
+
};
|
|
108
|
+
//#endregion
|
|
109
|
+
//#region src/core/extract-credentials.d.ts
|
|
110
|
+
/**
|
|
111
|
+
* Extracts authentication credentials from an incoming HTTP request.
|
|
112
|
+
*
|
|
113
|
+
* Reads two headers:
|
|
114
|
+
* - `Authorization: Bearer <token>` → extracted as `token`
|
|
115
|
+
* - `apikey: <key>` → extracted as `apikey`
|
|
116
|
+
*
|
|
117
|
+
* This is a pure extraction step — no validation or verification is performed.
|
|
118
|
+
* Pass the result to {@link verifyCredentials} to validate against allowed auth modes.
|
|
119
|
+
*
|
|
120
|
+
* @param request - The incoming HTTP request.
|
|
121
|
+
* @returns The extracted {@link Credentials}. Fields are `null` when the corresponding header is absent.
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
124
|
+
* ```ts
|
|
125
|
+
* import { extractCredentials } from '@supabase/server/core'
|
|
126
|
+
*
|
|
127
|
+
* const creds = extractCredentials(request)
|
|
128
|
+
* console.log(creds.token) // "eyJhbGci..." or null
|
|
129
|
+
* console.log(creds.apikey) // "sb-abc123-publishable-..." or null
|
|
130
|
+
* ```
|
|
131
|
+
*/
|
|
132
|
+
declare function extractCredentials(request: Request): Credentials;
|
|
133
|
+
//#endregion
|
|
134
|
+
//#region src/core/verify-credentials.d.ts
|
|
135
|
+
/**
|
|
136
|
+
* Options for {@link verifyCredentials}.
|
|
137
|
+
*/
|
|
138
|
+
interface VerifyCredentialsOptions {
|
|
139
|
+
/**
|
|
140
|
+
* Auth mode(s) to try. Modes are attempted in order — the first match wins.
|
|
141
|
+
*
|
|
142
|
+
* @see {@link AllowWithKey} for the full syntax including named keys.
|
|
143
|
+
*/
|
|
144
|
+
allow: AllowWithKey | AllowWithKey[];
|
|
145
|
+
/** Optional environment overrides (passed through to {@link resolveEnv}). */
|
|
146
|
+
env?: Partial<SupabaseEnv>;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Verifies pre-extracted credentials against one or more allowed auth modes.
|
|
150
|
+
*
|
|
151
|
+
* Tries each mode in order — first match wins. Use {@link verifyAuth} to extract
|
|
152
|
+
* and verify in a single call.
|
|
153
|
+
*
|
|
154
|
+
* @param credentials - The credentials to verify (from {@link extractCredentials}).
|
|
155
|
+
* @param options - Allowed auth modes and optional env overrides.
|
|
156
|
+
* @returns `{ data: AuthResult, error: null }` on success, `{ data: null, error: AuthError }` on failure.
|
|
157
|
+
*
|
|
158
|
+
* @example
|
|
159
|
+
* ```ts
|
|
160
|
+
* const credentials = extractCredentials(request)
|
|
161
|
+
* const { data: auth, error } = await verifyCredentials(credentials, {
|
|
162
|
+
* allow: ['user', 'public'],
|
|
163
|
+
* })
|
|
164
|
+
* if (error) {
|
|
165
|
+
* return Response.json({ error: error.message }, { status: error.status })
|
|
166
|
+
* }
|
|
167
|
+
* ```
|
|
168
|
+
*/
|
|
169
|
+
declare function verifyCredentials(credentials: Credentials, options: VerifyCredentialsOptions): Promise<{
|
|
170
|
+
data: AuthResult;
|
|
171
|
+
error: null;
|
|
172
|
+
} | {
|
|
173
|
+
data: null;
|
|
174
|
+
error: AuthError;
|
|
175
|
+
}>;
|
|
176
|
+
//#endregion
|
|
177
|
+
//#region src/core/verify-auth.d.ts
|
|
178
|
+
/**
|
|
179
|
+
* Options for {@link verifyAuth}.
|
|
180
|
+
*/
|
|
181
|
+
interface VerifyAuthOptions {
|
|
182
|
+
/**
|
|
183
|
+
* Auth mode(s) to try. Modes are attempted in order — the first match wins.
|
|
184
|
+
*
|
|
185
|
+
* @see {@link AllowWithKey} for the full syntax including named keys.
|
|
186
|
+
*/
|
|
187
|
+
allow: AllowWithKey | AllowWithKey[];
|
|
188
|
+
/** Optional environment overrides (passed through to {@link resolveEnv}). */
|
|
189
|
+
env?: Partial<SupabaseEnv>;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Extracts credentials from a request and verifies them in a single step.
|
|
193
|
+
*
|
|
194
|
+
* This is a convenience function that combines {@link extractCredentials} and
|
|
195
|
+
* {@link verifyCredentials}. Use it when you want the full auth flow without
|
|
196
|
+
* needing to inspect the raw credentials.
|
|
197
|
+
*
|
|
198
|
+
* @param request - The incoming HTTP request.
|
|
199
|
+
* @param options - Auth modes to accept and optional environment overrides.
|
|
200
|
+
*
|
|
201
|
+
* @returns A result tuple: `{ data, error }`.
|
|
202
|
+
* - On success: `{ data: AuthResult, error: null }`
|
|
203
|
+
* - On failure: `{ data: null, error: AuthError }`
|
|
204
|
+
*
|
|
205
|
+
* @example
|
|
206
|
+
* ```ts
|
|
207
|
+
* import { verifyAuth } from '@supabase/server/core'
|
|
208
|
+
*
|
|
209
|
+
* const { data: auth, error } = await verifyAuth(request, {
|
|
210
|
+
* allow: 'user',
|
|
211
|
+
* })
|
|
212
|
+
*
|
|
213
|
+
* if (error) {
|
|
214
|
+
* return Response.json({ error: error.message }, { status: error.status })
|
|
215
|
+
* }
|
|
216
|
+
*
|
|
217
|
+
* console.log(auth.userClaims!.id) // "d0f1a2b3-..."
|
|
218
|
+
* ```
|
|
219
|
+
*/
|
|
220
|
+
declare function verifyAuth(request: Request, options: VerifyAuthOptions): Promise<{
|
|
221
|
+
data: AuthResult;
|
|
222
|
+
error: null;
|
|
223
|
+
} | {
|
|
224
|
+
data: null;
|
|
225
|
+
error: AuthError;
|
|
226
|
+
}>;
|
|
227
|
+
//#endregion
|
|
228
|
+
//#region src/core/create-context-client.d.ts
|
|
229
|
+
/**
|
|
230
|
+
* Creates a Supabase client scoped to the caller's context.
|
|
231
|
+
*
|
|
232
|
+
* Configured with a publishable key and (optionally) the caller's JWT,
|
|
233
|
+
* so Row-Level Security policies apply. Session persistence is disabled
|
|
234
|
+
* (stateless, one client per request).
|
|
235
|
+
*
|
|
236
|
+
* @param token - The caller's JWT, or `null` for anonymous access.
|
|
237
|
+
* @param env - Optional environment overrides (passed through to {@link resolveEnv}).
|
|
238
|
+
* @param keyName - Name of the publishable key to use. Falls back to `"default"`, then first available.
|
|
239
|
+
* @returns A configured {@link SupabaseClient} with RLS enforced.
|
|
240
|
+
* @throws {@link EnvError} If `SUPABASE_URL` is missing or the specified publishable key is not found.
|
|
241
|
+
*
|
|
242
|
+
* @example
|
|
243
|
+
* ```ts
|
|
244
|
+
* const { data: auth } = await verifyAuth(request, { allow: 'user' })
|
|
245
|
+
* const supabase = createContextClient(auth.token)
|
|
246
|
+
* const { data } = await supabase.rpc('get_my_items')
|
|
247
|
+
* ```
|
|
248
|
+
*/
|
|
249
|
+
declare function createContextClient<Database = unknown>(token?: string | null, env?: Partial<SupabaseEnv>, keyName?: string | null): SupabaseClient<Database>;
|
|
250
|
+
//#endregion
|
|
251
|
+
//#region src/core/create-admin-client.d.ts
|
|
252
|
+
/**
|
|
253
|
+
* Creates an admin Supabase client that bypasses Row-Level Security.
|
|
254
|
+
*
|
|
255
|
+
* Uses a secret key for authentication, giving full access to all data.
|
|
256
|
+
* Session persistence is disabled (stateless, one client per request).
|
|
257
|
+
*
|
|
258
|
+
* @param env - Optional environment overrides (passed through to {@link resolveEnv}).
|
|
259
|
+
* @param keyName - Name of the secret key to use. Falls back to `"default"`, then first available.
|
|
260
|
+
* @returns A configured {@link SupabaseClient} with admin (service-role) privileges.
|
|
261
|
+
* @throws {@link EnvError} If `SUPABASE_URL` is missing or the specified secret key is not found.
|
|
262
|
+
*
|
|
263
|
+
* @example
|
|
264
|
+
* ```ts
|
|
265
|
+
* const supabaseAdmin = createAdminClient()
|
|
266
|
+
* const { data } = await supabaseAdmin.from('audit_log').insert({ action: 'user_login' })
|
|
267
|
+
* ```
|
|
268
|
+
*/
|
|
269
|
+
declare function createAdminClient<Database = unknown>(env?: Partial<SupabaseEnv>, keyName?: string | null): SupabaseClient<Database>;
|
|
270
|
+
//#endregion
|
|
271
|
+
export { extractCredentials as a, EnvError as c, verifyCredentials as i, createContextClient as n, resolveEnv as o, verifyAuth as r, AuthError as s, createAdminClient as t };
|