@dailyautomations/auth 1.0.0 → 1.1.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/dist/nextjs/cookies.d.ts +26 -0
- package/dist/nextjs/cookies.d.ts.map +1 -0
- package/dist/nextjs/cookies.js +78 -0
- package/dist/nextjs/cookies.js.map +1 -0
- package/dist/nextjs/index.d.ts +42 -0
- package/dist/nextjs/index.d.ts.map +1 -0
- package/dist/nextjs/index.js +64 -0
- package/dist/nextjs/index.js.map +1 -0
- package/dist/nextjs/middleware.d.ts +32 -0
- package/dist/nextjs/middleware.d.ts.map +1 -0
- package/dist/nextjs/middleware.js +118 -0
- package/dist/nextjs/middleware.js.map +1 -0
- package/dist/nextjs/route.d.ts +60 -0
- package/dist/nextjs/route.d.ts.map +1 -0
- package/dist/nextjs/route.js +143 -0
- package/dist/nextjs/route.js.map +1 -0
- package/dist/nextjs/server.d.ts +36 -0
- package/dist/nextjs/server.d.ts.map +1 -0
- package/dist/nextjs/server.js +114 -0
- package/dist/nextjs/server.js.map +1 -0
- package/dist/nextjs/session.d.ts +40 -0
- package/dist/nextjs/session.d.ts.map +1 -0
- package/dist/nextjs/session.js +121 -0
- package/dist/nextjs/session.js.map +1 -0
- package/dist/nextjs/types.d.ts +67 -0
- package/dist/nextjs/types.d.ts.map +1 -0
- package/dist/nextjs/types.js +7 -0
- package/dist/nextjs/types.js.map +1 -0
- package/package.json +15 -1
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @daily/auth/nextjs Cookie Utilities
|
|
3
|
+
* Helpers for Supabase SSR cookie handling
|
|
4
|
+
*/
|
|
5
|
+
import type { CookieMethods, CookieOptions } from './types.js';
|
|
6
|
+
/**
|
|
7
|
+
* Parse cookies from a cookie header string
|
|
8
|
+
*/
|
|
9
|
+
export declare function parseCookies(cookieHeader: string | null): Map<string, string>;
|
|
10
|
+
/**
|
|
11
|
+
* Serialize a cookie to a Set-Cookie header value
|
|
12
|
+
*/
|
|
13
|
+
export declare function serializeCookie(options: CookieOptions): string;
|
|
14
|
+
/**
|
|
15
|
+
* Create cookie methods adapter for Next.js cookies() function
|
|
16
|
+
* Works with the ReadonlyRequestCookies from next/headers
|
|
17
|
+
*/
|
|
18
|
+
export declare function createCookieAdapter(getCookie: (name: string) => {
|
|
19
|
+
name: string;
|
|
20
|
+
value: string;
|
|
21
|
+
} | undefined, setCookie: (name: string, value: string, options?: Record<string, unknown>) => void, deleteCookie: (name: string, options?: Record<string, unknown>) => void): CookieMethods;
|
|
22
|
+
/**
|
|
23
|
+
* Default cookie options for auth tokens
|
|
24
|
+
*/
|
|
25
|
+
export declare const DEFAULT_COOKIE_OPTIONS: Partial<CookieOptions>;
|
|
26
|
+
//# sourceMappingURL=cookies.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cookies.d.ts","sourceRoot":"","sources":["../../src/nextjs/cookies.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAE/D;;GAEG;AACH,wBAAgB,YAAY,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAY7E;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,aAAa,GAAG,MAAM,CAuB9D;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CACjC,SAAS,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,EACxE,SAAS,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI,EACnF,YAAY,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI,GACtE,aAAa,CAYf;AAED;;GAEG;AACH,eAAO,MAAM,sBAAsB,EAAE,OAAO,CAAC,aAAa,CAMzD,CAAC"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @daily/auth/nextjs Cookie Utilities
|
|
4
|
+
* Helpers for Supabase SSR cookie handling
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.DEFAULT_COOKIE_OPTIONS = void 0;
|
|
8
|
+
exports.parseCookies = parseCookies;
|
|
9
|
+
exports.serializeCookie = serializeCookie;
|
|
10
|
+
exports.createCookieAdapter = createCookieAdapter;
|
|
11
|
+
/**
|
|
12
|
+
* Parse cookies from a cookie header string
|
|
13
|
+
*/
|
|
14
|
+
function parseCookies(cookieHeader) {
|
|
15
|
+
const cookies = new Map();
|
|
16
|
+
if (!cookieHeader)
|
|
17
|
+
return cookies;
|
|
18
|
+
cookieHeader.split(';').forEach((cookie) => {
|
|
19
|
+
const [name, ...rest] = cookie.trim().split('=');
|
|
20
|
+
if (name && rest.length > 0) {
|
|
21
|
+
cookies.set(name, rest.join('='));
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
return cookies;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Serialize a cookie to a Set-Cookie header value
|
|
28
|
+
*/
|
|
29
|
+
function serializeCookie(options) {
|
|
30
|
+
let cookie = `${options.name}=${options.value}`;
|
|
31
|
+
if (options.maxAge !== undefined) {
|
|
32
|
+
cookie += `; Max-Age=${options.maxAge}`;
|
|
33
|
+
}
|
|
34
|
+
if (options.path) {
|
|
35
|
+
cookie += `; Path=${options.path}`;
|
|
36
|
+
}
|
|
37
|
+
if (options.domain) {
|
|
38
|
+
cookie += `; Domain=${options.domain}`;
|
|
39
|
+
}
|
|
40
|
+
if (options.secure) {
|
|
41
|
+
cookie += '; Secure';
|
|
42
|
+
}
|
|
43
|
+
if (options.httpOnly) {
|
|
44
|
+
cookie += '; HttpOnly';
|
|
45
|
+
}
|
|
46
|
+
if (options.sameSite) {
|
|
47
|
+
cookie += `; SameSite=${options.sameSite}`;
|
|
48
|
+
}
|
|
49
|
+
return cookie;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Create cookie methods adapter for Next.js cookies() function
|
|
53
|
+
* Works with the ReadonlyRequestCookies from next/headers
|
|
54
|
+
*/
|
|
55
|
+
function createCookieAdapter(getCookie, setCookie, deleteCookie) {
|
|
56
|
+
return {
|
|
57
|
+
get(name) {
|
|
58
|
+
return getCookie(name);
|
|
59
|
+
},
|
|
60
|
+
set(name, value, options) {
|
|
61
|
+
setCookie(name, value, options);
|
|
62
|
+
},
|
|
63
|
+
remove(name, options) {
|
|
64
|
+
deleteCookie(name, options);
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Default cookie options for auth tokens
|
|
70
|
+
*/
|
|
71
|
+
exports.DEFAULT_COOKIE_OPTIONS = {
|
|
72
|
+
path: '/',
|
|
73
|
+
httpOnly: true,
|
|
74
|
+
secure: process.env.NODE_ENV === 'production',
|
|
75
|
+
sameSite: 'lax',
|
|
76
|
+
maxAge: 60 * 60 * 24 * 7, // 7 days
|
|
77
|
+
};
|
|
78
|
+
//# sourceMappingURL=cookies.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cookies.js","sourceRoot":"","sources":["../../src/nextjs/cookies.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAOH,oCAYC;AAKD,0CAuBC;AAMD,kDAgBC;AAjED;;GAEG;AACH,SAAgB,YAAY,CAAC,YAA2B;IACtD,MAAM,OAAO,GAAG,IAAI,GAAG,EAAkB,CAAC;IAC1C,IAAI,CAAC,YAAY;QAAE,OAAO,OAAO,CAAC;IAElC,YA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jC,SAAwE,EACxE,SAAmF,EACnF,YAAuE;IAEvE,OAAO;QACL,GAAG,CAAC,IAAY;YACd,OAAO,SAAS,CAAC,IAAI,CAAC,CAAC;QACzB,CAAC;QACD,GAAG,CAAC,IAAY,EAAE,KAAa,EAAE,OAA+C;YAC9E,SAAS,CAAC,IAAI,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;QAClC,CAAC;QACD,MAAM,CAAC,IAAY,EAAE,OAA0D;YAC7E,YAAY,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QAC9B,CAAC;KACF,CAAC;AACJ,CAAC;AAED;;GAEG;AACU,QAAA,sBAAsB,GAA2B;IAC5D,IAAI,EAAE,GAAG;IACT,QAAQ,EAAE,IAAI;IACd,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY;IAC7C,QAAQ,EAAE,KAAK;IACf,MAAM,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,EAAE,SAAS;CACpC,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @daily/auth/nextjs
|
|
3
|
+
* Next.js SSR authentication for Daily applications
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* // Server Component
|
|
7
|
+
* import { cookies } from 'next/headers';
|
|
8
|
+
* import { getServerSession } from '@dailyautomations/auth/nextjs';
|
|
9
|
+
*
|
|
10
|
+
* export default async function Page() {
|
|
11
|
+
* const cookieStore = await cookies();
|
|
12
|
+
* const session = await getServerSession(authOptions, cookieStore);
|
|
13
|
+
* if (!session) redirect('/login');
|
|
14
|
+
* return <div>Hello {session.user.email}</div>;
|
|
15
|
+
* }
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* // Middleware
|
|
19
|
+
* import { createDailyMiddleware } from '@dailyautomations/auth/nextjs';
|
|
20
|
+
*
|
|
21
|
+
* export const middleware = createDailyMiddleware({
|
|
22
|
+
* supabaseUrl: process.env.NEXT_PUBLIC_SUPABASE_URL!,
|
|
23
|
+
* supabaseAnonKey: process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
|
|
24
|
+
* publicPaths: ['/login', '/signup'],
|
|
25
|
+
* loginUrl: '/login',
|
|
26
|
+
* });
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* // Route Handler
|
|
30
|
+
* import { withAuth, ApiResponse } from '@dailyautomations/auth/nextjs';
|
|
31
|
+
*
|
|
32
|
+
* export const GET = withAuth(authOptions, async (request, { user }) => {
|
|
33
|
+
* return ApiResponse.ok({ email: user.email });
|
|
34
|
+
* });
|
|
35
|
+
*/
|
|
36
|
+
export { createDailyServerClient, createDailyAdminClient, extractProjectRef, } from './server.js';
|
|
37
|
+
export { createDailyMiddleware, createMiddlewareMatcher, } from './middleware.js';
|
|
38
|
+
export { getServerSession, requireServerSession, isAuthenticated, } from './session.js';
|
|
39
|
+
export { withAuth, createAuthHandler, ApiResponse, } from './route.js';
|
|
40
|
+
export { parseCookies, serializeCookie, createCookieAdapter, DEFAULT_COOKIE_OPTIONS, } from './cookies.js';
|
|
41
|
+
export type { ServerAuthContext, ServerSessionResult, DailyServerClientOptions, DailyMiddlewareOptions, AuthenticatedHandler, WithAuthOptions, CookieOptions, CookieMethods, } from './types.js';
|
|
42
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/nextjs/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAGH,OAAO,EACL,uBAAuB,EACvB,sBAAsB,EACtB,iBAAiB,GAClB,MAAM,aAAa,CAAC;AAGrB,OAAO,EACL,qBAAqB,EACrB,uBAAuB,GACxB,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EACL,gBAAgB,EAChB,oBAAoB,EACpB,eAAe,GAChB,MAAM,cAAc,CAAC;AAGtB,OAAO,EACL,QAAQ,EACR,iBAAiB,EACjB,WAAW,GACZ,MAAM,YAAY,CAAC;AAGpB,OAAO,EACL,YAAY,EACZ,eAAe,EACf,mBAAmB,EACnB,sBAAsB,GACvB,MAAM,cAAc,CAAC;AAGtB,YAAY,EACV,iBAAiB,EACjB,mBAAmB,EACnB,wBAAwB,EACxB,sBAAsB,EACtB,oBAAoB,EACpB,eAAe,EACf,aAAa,EACb,aAAa,GACd,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @daily/auth/nextjs
|
|
4
|
+
* Next.js SSR authentication for Daily applications
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* // Server Component
|
|
8
|
+
* import { cookies } from 'next/headers';
|
|
9
|
+
* import { getServerSession } from '@dailyautomations/auth/nextjs';
|
|
10
|
+
*
|
|
11
|
+
* export default async function Page() {
|
|
12
|
+
* const cookieStore = await cookies();
|
|
13
|
+
* const session = await getServerSession(authOptions, cookieStore);
|
|
14
|
+
* if (!session) redirect('/login');
|
|
15
|
+
* return <div>Hello {session.user.email}</div>;
|
|
16
|
+
* }
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* // Middleware
|
|
20
|
+
* import { createDailyMiddleware } from '@dailyautomations/auth/nextjs';
|
|
21
|
+
*
|
|
22
|
+
* export const middleware = createDailyMiddleware({
|
|
23
|
+
* supabaseUrl: process.env.NEXT_PUBLIC_SUPABASE_URL!,
|
|
24
|
+
* supabaseAnonKey: process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
|
|
25
|
+
* publicPaths: ['/login', '/signup'],
|
|
26
|
+
* loginUrl: '/login',
|
|
27
|
+
* });
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* // Route Handler
|
|
31
|
+
* import { withAuth, ApiResponse } from '@dailyautomations/auth/nextjs';
|
|
32
|
+
*
|
|
33
|
+
* export const GET = withAuth(authOptions, async (request, { user }) => {
|
|
34
|
+
* return ApiResponse.ok({ email: user.email });
|
|
35
|
+
* });
|
|
36
|
+
*/
|
|
37
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
+
exports.DEFAULT_COOKIE_OPTIONS = exports.createCookieAdapter = exports.serializeCookie = exports.parseCookies = exports.ApiResponse = exports.createAuthHandler = exports.withAuth = exports.isAuthenticated = exports.requireServerSession = exports.getServerSession = exports.createMiddlewareMatcher = exports.createDailyMiddleware = exports.extractProjectRef = exports.createDailyAdminClient = exports.createDailyServerClient = void 0;
|
|
39
|
+
// Server client
|
|
40
|
+
var server_js_1 = require("./server.js");
|
|
41
|
+
Object.defineProperty(exports, "createDailyServerClient", { enumerable: true, get: function () { return server_js_1.createDailyServerClient; } });
|
|
42
|
+
Object.defineProperty(exports, "createDailyAdminClient", { enumerable: true, get: function () { return server_js_1.createDailyAdminClient; } });
|
|
43
|
+
Object.defineProperty(exports, "extractProjectRef", { enumerable: true, get: function () { return server_js_1.extractProjectRef; } });
|
|
44
|
+
// Middleware
|
|
45
|
+
var middleware_js_1 = require("./middleware.js");
|
|
46
|
+
Object.defineProperty(exports, "createDailyMiddleware", { enumerable: true, get: function () { return middleware_js_1.createDailyMiddleware; } });
|
|
47
|
+
Object.defineProperty(exports, "createMiddlewareMatcher", { enumerable: true, get: function () { return middleware_js_1.createMiddlewareMatcher; } });
|
|
48
|
+
// Session
|
|
49
|
+
var session_js_1 = require("./session.js");
|
|
50
|
+
Object.defineProperty(exports, "getServerSession", { enumerable: true, get: function () { return session_js_1.getServerSession; } });
|
|
51
|
+
Object.defineProperty(exports, "requireServerSession", { enumerable: true, get: function () { return session_js_1.requireServerSession; } });
|
|
52
|
+
Object.defineProperty(exports, "isAuthenticated", { enumerable: true, get: function () { return session_js_1.isAuthenticated; } });
|
|
53
|
+
// Route handlers
|
|
54
|
+
var route_js_1 = require("./route.js");
|
|
55
|
+
Object.defineProperty(exports, "withAuth", { enumerable: true, get: function () { return route_js_1.withAuth; } });
|
|
56
|
+
Object.defineProperty(exports, "createAuthHandler", { enumerable: true, get: function () { return route_js_1.createAuthHandler; } });
|
|
57
|
+
Object.defineProperty(exports, "ApiResponse", { enumerable: true, get: function () { return route_js_1.ApiResponse; } });
|
|
58
|
+
// Cookie utilities
|
|
59
|
+
var cookies_js_1 = require("./cookies.js");
|
|
60
|
+
Object.defineProperty(exports, "parseCookies", { enumerable: true, get: function () { return cookies_js_1.parseCookies; } });
|
|
61
|
+
Object.defineProperty(exports, "serializeCookie", { enumerable: true, get: function () { return cookies_js_1.serializeCookie; } });
|
|
62
|
+
Object.defineProperty(exports, "createCookieAdapter", { enumerable: true, get: function () { return cookies_js_1.createCookieAdapter; } });
|
|
63
|
+
Object.defineProperty(exports, "DEFAULT_COOKIE_OPTIONS", { enumerable: true, get: function () { return cookies_js_1.DEFAULT_COOKIE_OPTIONS; } });
|
|
64
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/nextjs/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;;;AAEH,gBAAgB;AAChB,yCAIqB;AAHnB,oHAAA,uBAAuB,OAAA;AACvB,mHAAA,sBAAsB,OAAA;AACtB,8GAAA,iBAAiB,OAAA;AAGnB,aAAa;AACb,iDAGyB;AAFvB,sHAAA,qBAAqB,OAAA;AACrB,wHAAA,uBAAuB,OAAA;AAGzB,UAAU;AACV,2CAIsB;AAHpB,8GAAA,gBAAgB,OAAA;AAChB,kHAAA,oBAAoB,OAAA;AACpB,6GAAA,eAAe,OAAA;AAGjB,iBAAiB;AACjB,uCAIoB;AAHlB,oGAAA,QAAQ,OAAA;AACR,6GAAA,iBAAiB,OAAA;AACjB,uGAAA,WAAW,OAAA;AAGb,mBAAmB;AACnB,2CAKsB;AAJpB,0GAAA,YAAY,OAAA;AACZ,6GAAA,eAAe,OAAA;AACf,iHAAA,mBAAmB,OAAA;AACnB,oHAAA,sBAAsB,OAAA"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @daily/auth/nextjs Middleware
|
|
3
|
+
* Next.js middleware for route protection
|
|
4
|
+
*/
|
|
5
|
+
import type { NextRequest } from 'next/server';
|
|
6
|
+
import { NextResponse } from 'next/server';
|
|
7
|
+
import type { DailyMiddlewareOptions } from './types.js';
|
|
8
|
+
/**
|
|
9
|
+
* Create Next.js middleware for route protection
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* // middleware.ts
|
|
13
|
+
* import { createDailyMiddleware } from '@daily/auth/nextjs';
|
|
14
|
+
*
|
|
15
|
+
* export const middleware = createDailyMiddleware({
|
|
16
|
+
* supabaseUrl: process.env.NEXT_PUBLIC_SUPABASE_URL!,
|
|
17
|
+
* supabaseAnonKey: process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
|
|
18
|
+
* publicPaths: ['/login', '/signup', '/api/health'],
|
|
19
|
+
* loginUrl: '/login',
|
|
20
|
+
* });
|
|
21
|
+
*
|
|
22
|
+
* export const config = {
|
|
23
|
+
* matcher: ['/((?!_next/static|_next/image|favicon.ico).*)'],
|
|
24
|
+
* };
|
|
25
|
+
*/
|
|
26
|
+
export declare function createDailyMiddleware(options: DailyMiddlewareOptions): (request: NextRequest) => Promise<NextResponse>;
|
|
27
|
+
/**
|
|
28
|
+
* Utility to create a matcher config for Next.js middleware
|
|
29
|
+
* Excludes static files and images by default
|
|
30
|
+
*/
|
|
31
|
+
export declare function createMiddlewareMatcher(additionalExclusions?: string[]): string[];
|
|
32
|
+
//# sourceMappingURL=middleware.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../../src/nextjs/middleware.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAGzD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,sBAAsB,IAQlC,SAAS,WAAW,KAAG,OAAO,CAAC,YAAY,CAAC,CA0D9E;AA4BD;;;GAGG;AACH,wBAAgB,uBAAuB,CACrC,oBAAoB,GAAE,MAAM,EAAO,GAClC,MAAM,EAAE,CAWV"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @daily/auth/nextjs Middleware
|
|
4
|
+
* Next.js middleware for route protection
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.createDailyMiddleware = createDailyMiddleware;
|
|
8
|
+
exports.createMiddlewareMatcher = createMiddlewareMatcher;
|
|
9
|
+
const ssr_1 = require("@supabase/ssr");
|
|
10
|
+
const server_1 = require("next/server");
|
|
11
|
+
/**
|
|
12
|
+
* Create Next.js middleware for route protection
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* // middleware.ts
|
|
16
|
+
* import { createDailyMiddleware } from '@daily/auth/nextjs';
|
|
17
|
+
*
|
|
18
|
+
* export const middleware = createDailyMiddleware({
|
|
19
|
+
* supabaseUrl: process.env.NEXT_PUBLIC_SUPABASE_URL!,
|
|
20
|
+
* supabaseAnonKey: process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
|
|
21
|
+
* publicPaths: ['/login', '/signup', '/api/health'],
|
|
22
|
+
* loginUrl: '/login',
|
|
23
|
+
* });
|
|
24
|
+
*
|
|
25
|
+
* export const config = {
|
|
26
|
+
* matcher: ['/((?!_next/static|_next/image|favicon.ico).*)'],
|
|
27
|
+
* };
|
|
28
|
+
*/
|
|
29
|
+
function createDailyMiddleware(options) {
|
|
30
|
+
const { supabaseUrl, supabaseAnonKey, publicPaths = [], loginUrl = '/login', } = options;
|
|
31
|
+
return async function middleware(request) {
|
|
32
|
+
// Create response to pass to supabase client
|
|
33
|
+
let response = server_1.NextResponse.next({
|
|
34
|
+
request: {
|
|
35
|
+
headers: request.headers,
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
const supabase = (0, ssr_1.createServerClient)(supabaseUrl, supabaseAnonKey, {
|
|
39
|
+
cookies: {
|
|
40
|
+
getAll() {
|
|
41
|
+
return request.cookies.getAll();
|
|
42
|
+
},
|
|
43
|
+
setAll(cookiesToSet) {
|
|
44
|
+
// Update request cookies
|
|
45
|
+
cookiesToSet.forEach(({ name, value }) => {
|
|
46
|
+
request.cookies.set(name, value);
|
|
47
|
+
});
|
|
48
|
+
// Create new response with updated cookies
|
|
49
|
+
response = server_1.NextResponse.next({
|
|
50
|
+
request: {
|
|
51
|
+
headers: request.headers,
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
// Set cookies on response
|
|
55
|
+
cookiesToSet.forEach(({ name, value, options: cookieOptions }) => {
|
|
56
|
+
response.cookies.set(name, value, cookieOptions);
|
|
57
|
+
});
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
// Check if path is public
|
|
62
|
+
const pathname = request.nextUrl.pathname;
|
|
63
|
+
const isPublic = isPublicPath(pathname, publicPaths);
|
|
64
|
+
if (isPublic) {
|
|
65
|
+
// Refresh session even on public paths (keeps tokens fresh)
|
|
66
|
+
await supabase.auth.getUser();
|
|
67
|
+
return response;
|
|
68
|
+
}
|
|
69
|
+
// Protected path - verify authentication
|
|
70
|
+
const { data: { user }, error } = await supabase.auth.getUser();
|
|
71
|
+
if (error || !user) {
|
|
72
|
+
// Store the original URL to redirect back after login
|
|
73
|
+
const redirectUrl = new URL(loginUrl, request.url);
|
|
74
|
+
redirectUrl.searchParams.set('redirectTo', pathname);
|
|
75
|
+
return server_1.NextResponse.redirect(redirectUrl);
|
|
76
|
+
}
|
|
77
|
+
// User is authenticated, continue
|
|
78
|
+
return response;
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Check if a path matches any public path patterns
|
|
83
|
+
*/
|
|
84
|
+
function isPublicPath(pathname, publicPaths) {
|
|
85
|
+
return publicPaths.some((pattern) => {
|
|
86
|
+
// Exact match
|
|
87
|
+
if (pattern === pathname) {
|
|
88
|
+
return true;
|
|
89
|
+
}
|
|
90
|
+
// Wildcard match: /api/* matches /api/anything
|
|
91
|
+
if (pattern.endsWith('*')) {
|
|
92
|
+
const prefix = pattern.slice(0, -1);
|
|
93
|
+
return pathname.startsWith(prefix);
|
|
94
|
+
}
|
|
95
|
+
// Wildcard match: /api/** matches /api/anything/nested
|
|
96
|
+
if (pattern.endsWith('**')) {
|
|
97
|
+
const prefix = pattern.slice(0, -2);
|
|
98
|
+
return pathname.startsWith(prefix);
|
|
99
|
+
}
|
|
100
|
+
return false;
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Utility to create a matcher config for Next.js middleware
|
|
105
|
+
* Excludes static files and images by default
|
|
106
|
+
*/
|
|
107
|
+
function createMiddlewareMatcher(additionalExclusions = []) {
|
|
108
|
+
const defaultExclusions = [
|
|
109
|
+
'_next/static',
|
|
110
|
+
'_next/image',
|
|
111
|
+
'favicon.ico',
|
|
112
|
+
'.*\\.(?:svg|png|jpg|jpeg|gif|webp)$',
|
|
113
|
+
...additionalExclusions,
|
|
114
|
+
];
|
|
115
|
+
const exclusionPattern = defaultExclusions.join('|');
|
|
116
|
+
return [`/((?!${exclusionPattern}).*)`];
|
|
117
|
+
}
|
|
118
|
+
//# sourceMappingURL=middleware.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"middleware.js","sourceRoot":"","sources":["../../src/nextjs/middleware.ts"],"names":[],"mappings":";AAAA;;;GAGG;;AA0BH,sDAkEC;AAgCD,0DAaC;AAvID,uCAAiF;AAEjF,wCAA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C3B,MAAM,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;YACpC,OAAO,QAAQ,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;QACrC,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;;GAGG;AACH,SAAgB,uBAAuB,CACrC,uBAAiC,EAAE;IAEnC,MAAM,iBAAiB,GAAG;QACxB,cAAc;QACd,aAAa;QACb,aAAa;QACb,qCAAqC;QACrC,GAAG,oBAAoB;KACxB,CAAC;IAEF,MAAM,gBAAgB,GAAG,iBAAiB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACrD,OAAO,CAAC,QAAQ,gBAAgB,MAAM,CAAC,CAAC;AAC1C,CAAC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @daily/auth/nextjs Route Handlers
|
|
3
|
+
* Utilities for protected API routes
|
|
4
|
+
*/
|
|
5
|
+
import type { DailyServerClientOptions, AuthenticatedHandler, WithAuthOptions } from './types.js';
|
|
6
|
+
/**
|
|
7
|
+
* Wrap a route handler to require authentication
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* // app/api/user/route.ts
|
|
11
|
+
* import { cookies } from 'next/headers';
|
|
12
|
+
* import { withAuth } from '@daily/auth/nextjs';
|
|
13
|
+
*
|
|
14
|
+
* const authOptions = {
|
|
15
|
+
* supabaseUrl: process.env.NEXT_PUBLIC_SUPABASE_URL!,
|
|
16
|
+
* supabaseAnonKey: process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
|
|
17
|
+
* serviceKey: process.env.SUPABASE_SERVICE_ROLE_KEY,
|
|
18
|
+
* };
|
|
19
|
+
*
|
|
20
|
+
* export const GET = withAuth(authOptions, async (request, { user, workspace }) => {
|
|
21
|
+
* return Response.json({ email: user.email, workspace: workspace?.name });
|
|
22
|
+
* });
|
|
23
|
+
*/
|
|
24
|
+
export declare function withAuth(options: DailyServerClientOptions, handler: AuthenticatedHandler, handlerOptions?: WithAuthOptions): (request: Request) => Promise<Response>;
|
|
25
|
+
/**
|
|
26
|
+
* Create a higher-order function that pre-configures auth options
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* // lib/auth.ts
|
|
30
|
+
* import { createAuthHandler } from '@daily/auth/nextjs';
|
|
31
|
+
*
|
|
32
|
+
* export const withAuth = createAuthHandler({
|
|
33
|
+
* supabaseUrl: process.env.NEXT_PUBLIC_SUPABASE_URL!,
|
|
34
|
+
* supabaseAnonKey: process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
|
|
35
|
+
* serviceKey: process.env.SUPABASE_SERVICE_ROLE_KEY,
|
|
36
|
+
* });
|
|
37
|
+
*
|
|
38
|
+
* // app/api/user/route.ts
|
|
39
|
+
* import { withAuth } from '@/lib/auth';
|
|
40
|
+
*
|
|
41
|
+
* export const GET = withAuth(async (request, { user }) => {
|
|
42
|
+
* return { email: user.email };
|
|
43
|
+
* });
|
|
44
|
+
*/
|
|
45
|
+
export declare function createAuthHandler(options: DailyServerClientOptions): (handler: AuthenticatedHandler, handlerOptions?: WithAuthOptions) => (request: Request) => Promise<Response>;
|
|
46
|
+
/**
|
|
47
|
+
* Standard API response helpers for consistency across routes
|
|
48
|
+
*/
|
|
49
|
+
export declare const ApiResponse: {
|
|
50
|
+
ok<T>(data: T, init?: ResponseInit): Response;
|
|
51
|
+
created<T>(data: T, init?: ResponseInit): Response;
|
|
52
|
+
noContent(init?: ResponseInit): Response;
|
|
53
|
+
badRequest(message: string, code?: string, details?: unknown): Response;
|
|
54
|
+
unauthorized(message?: string, code?: string): Response;
|
|
55
|
+
forbidden(message?: string, code?: string): Response;
|
|
56
|
+
notFound(message?: string, code?: string): Response;
|
|
57
|
+
conflict(message: string, code?: string): Response;
|
|
58
|
+
serverError(message?: string, code?: string): Response;
|
|
59
|
+
};
|
|
60
|
+
//# sourceMappingURL=route.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../src/nextjs/route.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAEV,wBAAwB,EACxB,oBAAoB,EACpB,eAAe,EAEhB,MAAM,YAAY,CAAC;AAGpB;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,QAAQ,CACtB,OAAO,EAAE,wBAAwB,EACjC,OAAO,EAAE,oBAAoB,EAC7B,cAAc,CAAC,EAAE,eAAe,GAC/B,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,CAkCzC;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,wBAAwB,IAE/D,SAAS,oBAAoB,EAC7B,iBAAiB,eAAe,KAC/B,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,CAG3C;AAoCD;;GAEG;AACH,eAAO,MAAM,WAAW;OACnB,CAAC,QAAQ,CAAC,SAAS,YAAY,GAAG,QAAQ;YAIrC,CAAC,QAAQ,CAAC,SAAS,YAAY,GAAG,QAAQ;qBAIjC,YAAY,GAAG,QAAQ;wBAIpB,MAAM,2BAAkC,OAAO,GAAG,QAAQ;mDAIf,QAAQ;gDAIjB,QAAQ;+CAIT,QAAQ;sBAI3C,MAAM,kBAAsB,QAAQ;kDAImB,QAAQ;CAGlF,CAAC"}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @daily/auth/nextjs Route Handlers
|
|
4
|
+
* Utilities for protected API routes
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.ApiResponse = void 0;
|
|
8
|
+
exports.withAuth = withAuth;
|
|
9
|
+
exports.createAuthHandler = createAuthHandler;
|
|
10
|
+
const session_js_1 = require("./session.js");
|
|
11
|
+
/**
|
|
12
|
+
* Wrap a route handler to require authentication
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* // app/api/user/route.ts
|
|
16
|
+
* import { cookies } from 'next/headers';
|
|
17
|
+
* import { withAuth } from '@daily/auth/nextjs';
|
|
18
|
+
*
|
|
19
|
+
* const authOptions = {
|
|
20
|
+
* supabaseUrl: process.env.NEXT_PUBLIC_SUPABASE_URL!,
|
|
21
|
+
* supabaseAnonKey: process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
|
|
22
|
+
* serviceKey: process.env.SUPABASE_SERVICE_ROLE_KEY,
|
|
23
|
+
* };
|
|
24
|
+
*
|
|
25
|
+
* export const GET = withAuth(authOptions, async (request, { user, workspace }) => {
|
|
26
|
+
* return Response.json({ email: user.email, workspace: workspace?.name });
|
|
27
|
+
* });
|
|
28
|
+
*/
|
|
29
|
+
function withAuth(options, handler, handlerOptions) {
|
|
30
|
+
return async (request) => {
|
|
31
|
+
// Get cookies from request headers
|
|
32
|
+
const cookieHeader = request.headers.get('cookie');
|
|
33
|
+
const cookieStore = createRequestCookieStore(cookieHeader);
|
|
34
|
+
const session = await (0, session_js_1.getServerSession)(options, cookieStore);
|
|
35
|
+
if (!session) {
|
|
36
|
+
if (handlerOptions?.onUnauthorized) {
|
|
37
|
+
return handlerOptions.onUnauthorized(request);
|
|
38
|
+
}
|
|
39
|
+
return Response.json({ error: 'Unauthorized', code: 'UNAUTHORIZED' }, { status: 401 });
|
|
40
|
+
}
|
|
41
|
+
try {
|
|
42
|
+
const result = await handler(request, session);
|
|
43
|
+
// If handler returns a Response, use it directly
|
|
44
|
+
if (result instanceof Response) {
|
|
45
|
+
return result;
|
|
46
|
+
}
|
|
47
|
+
// Otherwise, assume it's JSON-serializable
|
|
48
|
+
return Response.json(result);
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
// Let errors bubble up for Next.js error handling
|
|
52
|
+
throw error;
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Create a higher-order function that pre-configures auth options
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* // lib/auth.ts
|
|
61
|
+
* import { createAuthHandler } from '@daily/auth/nextjs';
|
|
62
|
+
*
|
|
63
|
+
* export const withAuth = createAuthHandler({
|
|
64
|
+
* supabaseUrl: process.env.NEXT_PUBLIC_SUPABASE_URL!,
|
|
65
|
+
* supabaseAnonKey: process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
|
|
66
|
+
* serviceKey: process.env.SUPABASE_SERVICE_ROLE_KEY,
|
|
67
|
+
* });
|
|
68
|
+
*
|
|
69
|
+
* // app/api/user/route.ts
|
|
70
|
+
* import { withAuth } from '@/lib/auth';
|
|
71
|
+
*
|
|
72
|
+
* export const GET = withAuth(async (request, { user }) => {
|
|
73
|
+
* return { email: user.email };
|
|
74
|
+
* });
|
|
75
|
+
*/
|
|
76
|
+
function createAuthHandler(options) {
|
|
77
|
+
return function configuredWithAuth(handler, handlerOptions) {
|
|
78
|
+
return withAuth(options, handler, handlerOptions);
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Create a simple cookie store from request cookie header
|
|
83
|
+
* For use in route handlers where next/headers cookies() isn't available
|
|
84
|
+
*/
|
|
85
|
+
function createRequestCookieStore(cookieHeader) {
|
|
86
|
+
const cookies = new Map();
|
|
87
|
+
if (cookieHeader) {
|
|
88
|
+
cookieHeader.split(';').forEach((cookie) => {
|
|
89
|
+
const [name, ...rest] = cookie.trim().split('=');
|
|
90
|
+
if (name && rest.length > 0) {
|
|
91
|
+
cookies.set(name, rest.join('='));
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
return {
|
|
96
|
+
get(name) {
|
|
97
|
+
const value = cookies.get(name);
|
|
98
|
+
return value ? { name, value } : undefined;
|
|
99
|
+
},
|
|
100
|
+
set() {
|
|
101
|
+
// Can't set cookies on request, this is handled by response
|
|
102
|
+
},
|
|
103
|
+
remove() {
|
|
104
|
+
// Can't remove cookies on request
|
|
105
|
+
},
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
// =============================================================================
|
|
109
|
+
// RESPONSE HELPERS
|
|
110
|
+
// =============================================================================
|
|
111
|
+
/**
|
|
112
|
+
* Standard API response helpers for consistency across routes
|
|
113
|
+
*/
|
|
114
|
+
exports.ApiResponse = {
|
|
115
|
+
ok(data, init) {
|
|
116
|
+
return Response.json(data, { status: 200, ...init });
|
|
117
|
+
},
|
|
118
|
+
created(data, init) {
|
|
119
|
+
return Response.json(data, { status: 201, ...init });
|
|
120
|
+
},
|
|
121
|
+
noContent(init) {
|
|
122
|
+
return new Response(null, { status: 204, ...init });
|
|
123
|
+
},
|
|
124
|
+
badRequest(message, code = 'BAD_REQUEST', details) {
|
|
125
|
+
return Response.json({ error: message, code, details }, { status: 400 });
|
|
126
|
+
},
|
|
127
|
+
unauthorized(message = 'Unauthorized', code = 'UNAUTHORIZED') {
|
|
128
|
+
return Response.json({ error: message, code }, { status: 401 });
|
|
129
|
+
},
|
|
130
|
+
forbidden(message = 'Forbidden', code = 'FORBIDDEN') {
|
|
131
|
+
return Response.json({ error: message, code }, { status: 403 });
|
|
132
|
+
},
|
|
133
|
+
notFound(message = 'Not found', code = 'NOT_FOUND') {
|
|
134
|
+
return Response.json({ error: message, code }, { status: 404 });
|
|
135
|
+
},
|
|
136
|
+
conflict(message, code = 'CONFLICT') {
|
|
137
|
+
return Response.json({ error: message, code }, { status: 409 });
|
|
138
|
+
},
|
|
139
|
+
serverError(message = 'Internal server error', code = 'INTERNAL_ERROR') {
|
|
140
|
+
return Response.json({ error: message, code }, { status: 500 });
|
|
141
|
+
},
|
|
142
|
+
};
|
|
143
|
+
//# sourceMappingURL=route.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"route.js","sourceRoot":"","sources":["../../src/nextjs/route.ts"],"names":[],"mappings":";AAA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AED,WAAW,CAAC,OAAO,GAAG,uBAAuB,EAAE,IAAI,GAAG,gBAAgB;QACpE,OAAO,QAAQ,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC;IAClE,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @daily/auth/nextjs Server Client
|
|
3
|
+
* Create Supabase client for Next.js server components and route handlers
|
|
4
|
+
*/
|
|
5
|
+
import { type SupabaseClient } from '@supabase/supabase-js';
|
|
6
|
+
import type { DailyServerClientOptions, CookieMethods } from './types.js';
|
|
7
|
+
/**
|
|
8
|
+
* Create a Supabase client for server components using cookies
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* // In a server component or route handler
|
|
12
|
+
* import { cookies } from 'next/headers';
|
|
13
|
+
* import { createDailyServerClient } from '@daily/auth/nextjs';
|
|
14
|
+
*
|
|
15
|
+
* export default async function Page() {
|
|
16
|
+
* const cookieStore = await cookies();
|
|
17
|
+
* const supabase = createDailyServerClient({
|
|
18
|
+
* supabaseUrl: process.env.NEXT_PUBLIC_SUPABASE_URL!,
|
|
19
|
+
* supabaseAnonKey: process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
|
|
20
|
+
* }, cookieStore);
|
|
21
|
+
*
|
|
22
|
+
* const { data: { user } } = await supabase.auth.getUser();
|
|
23
|
+
* }
|
|
24
|
+
*/
|
|
25
|
+
export declare function createDailyServerClient(options: DailyServerClientOptions, cookieStore: CookieMethods): SupabaseClient;
|
|
26
|
+
/**
|
|
27
|
+
* Create an admin Supabase client (bypasses RLS)
|
|
28
|
+
* Use this for server-side operations that need elevated privileges
|
|
29
|
+
*/
|
|
30
|
+
export declare function createDailyAdminClient(options: DailyServerClientOptions): SupabaseClient;
|
|
31
|
+
/**
|
|
32
|
+
* Extract project reference from Supabase URL
|
|
33
|
+
* https://abc123.supabase.co -> abc123
|
|
34
|
+
*/
|
|
35
|
+
export declare function extractProjectRef(supabaseUrl: string): string;
|
|
36
|
+
//# sourceMappingURL=server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/nextjs/server.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAgB,KAAK,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC1E,OAAO,KAAK,EAAE,wBAAwB,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAE1E;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,wBAAwB,EACjC,WAAW,EAAE,aAAa,GACzB,cAAc,CA4ChB;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,wBAAwB,GAAG,cAAc,CAaxF;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAuB7D"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @daily/auth/nextjs Server Client
|
|
4
|
+
* Create Supabase client for Next.js server components and route handlers
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.createDailyServerClient = createDailyServerClient;
|
|
8
|
+
exports.createDailyAdminClient = createDailyAdminClient;
|
|
9
|
+
exports.extractProjectRef = extractProjectRef;
|
|
10
|
+
const ssr_1 = require("@supabase/ssr");
|
|
11
|
+
const supabase_js_1 = require("@supabase/supabase-js");
|
|
12
|
+
/**
|
|
13
|
+
* Create a Supabase client for server components using cookies
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* // In a server component or route handler
|
|
17
|
+
* import { cookies } from 'next/headers';
|
|
18
|
+
* import { createDailyServerClient } from '@daily/auth/nextjs';
|
|
19
|
+
*
|
|
20
|
+
* export default async function Page() {
|
|
21
|
+
* const cookieStore = await cookies();
|
|
22
|
+
* const supabase = createDailyServerClient({
|
|
23
|
+
* supabaseUrl: process.env.NEXT_PUBLIC_SUPABASE_URL!,
|
|
24
|
+
* supabaseAnonKey: process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
|
|
25
|
+
* }, cookieStore);
|
|
26
|
+
*
|
|
27
|
+
* const { data: { user } } = await supabase.auth.getUser();
|
|
28
|
+
* }
|
|
29
|
+
*/
|
|
30
|
+
function createDailyServerClient(options, cookieStore) {
|
|
31
|
+
const { supabaseUrl, supabaseAnonKey } = options;
|
|
32
|
+
return (0, ssr_1.createServerClient)(supabaseUrl, supabaseAnonKey, {
|
|
33
|
+
cookies: {
|
|
34
|
+
getAll() {
|
|
35
|
+
// @supabase/ssr expects getAll to return array of {name, value}
|
|
36
|
+
// We need to get all auth-related cookies
|
|
37
|
+
const allCookies = [];
|
|
38
|
+
// Get the main auth token cookie
|
|
39
|
+
// Supabase uses: sb-{project-ref}-auth-token
|
|
40
|
+
const projectRef = extractProjectRef(supabaseUrl);
|
|
41
|
+
const authCookieName = `sb-${projectRef}-auth-token`;
|
|
42
|
+
const authCookie = cookieStore.get(authCookieName);
|
|
43
|
+
if (authCookie) {
|
|
44
|
+
allCookies.push(authCookie);
|
|
45
|
+
}
|
|
46
|
+
// Also check for chunked cookies (large tokens are split)
|
|
47
|
+
for (let i = 0; i < 10; i++) {
|
|
48
|
+
const chunkCookie = cookieStore.get(`${authCookieName}.${i}`);
|
|
49
|
+
if (chunkCookie) {
|
|
50
|
+
allCookies.push(chunkCookie);
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return allCookies;
|
|
57
|
+
},
|
|
58
|
+
setAll(cookiesToSet) {
|
|
59
|
+
try {
|
|
60
|
+
cookiesToSet.forEach(({ name, value, options: cookieOptions }) => {
|
|
61
|
+
cookieStore.set(name, value, cookieOptions);
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
// In server components, cookies can't be set (read-only)
|
|
66
|
+
// This is expected behavior, silently ignore
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Create an admin Supabase client (bypasses RLS)
|
|
74
|
+
* Use this for server-side operations that need elevated privileges
|
|
75
|
+
*/
|
|
76
|
+
function createDailyAdminClient(options) {
|
|
77
|
+
const { supabaseUrl, serviceKey } = options;
|
|
78
|
+
if (!serviceKey) {
|
|
79
|
+
throw new Error('serviceKey is required for admin client');
|
|
80
|
+
}
|
|
81
|
+
return (0, supabase_js_1.createClient)(supabaseUrl, serviceKey, {
|
|
82
|
+
auth: {
|
|
83
|
+
autoRefreshToken: false,
|
|
84
|
+
persistSession: false,
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Extract project reference from Supabase URL
|
|
90
|
+
* https://abc123.supabase.co -> abc123
|
|
91
|
+
*/
|
|
92
|
+
function extractProjectRef(supabaseUrl) {
|
|
93
|
+
try {
|
|
94
|
+
const url = new URL(supabaseUrl);
|
|
95
|
+
const hostname = url.hostname;
|
|
96
|
+
// Handle custom domains
|
|
97
|
+
if (!hostname.includes('supabase.co') && !hostname.includes('supabase.com')) {
|
|
98
|
+
// For custom domains, use the full hostname as the ref
|
|
99
|
+
return hostname.replace(/\./g, '-');
|
|
100
|
+
}
|
|
101
|
+
// Standard Supabase URL: https://project-ref.supabase.co
|
|
102
|
+
const parts = hostname.split('.');
|
|
103
|
+
if (parts.length >= 3) {
|
|
104
|
+
return parts[0];
|
|
105
|
+
}
|
|
106
|
+
// Fallback: use the hostname without TLD
|
|
107
|
+
return parts[0] || 'default';
|
|
108
|
+
}
|
|
109
|
+
catch {
|
|
110
|
+
// If URL parsing fails, generate a fallback
|
|
111
|
+
return 'default';
|
|
112
|
+
}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M,IAAI,CAAC,EAAE,CAAC;YACtB,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;QAED,yCAAyC;QACzC,OAAO,KAAK,CAAC,CAAC,CAAC,IAAI,SAAS,CAAC;IAC/B,CAAC;IAAC,MAAM,CAAC;QACP,4CAA4C;QAC5C,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @daily/auth/nextjs Session
|
|
3
|
+
* Server-side session retrieval for Next.js
|
|
4
|
+
*/
|
|
5
|
+
import type { ServerAuthContext, ServerSessionResult, DailyServerClientOptions, CookieMethods } from './types.js';
|
|
6
|
+
/**
|
|
7
|
+
* Get the current user session in a server component or route handler
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* // In a server component
|
|
11
|
+
* import { cookies } from 'next/headers';
|
|
12
|
+
* import { getServerSession } from '@daily/auth/nextjs';
|
|
13
|
+
*
|
|
14
|
+
* export default async function Page() {
|
|
15
|
+
* const cookieStore = await cookies();
|
|
16
|
+
* const session = await getServerSession({
|
|
17
|
+
* supabaseUrl: process.env.NEXT_PUBLIC_SUPABASE_URL!,
|
|
18
|
+
* supabaseAnonKey: process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
|
|
19
|
+
* serviceKey: process.env.SUPABASE_SERVICE_ROLE_KEY,
|
|
20
|
+
* }, cookieStore);
|
|
21
|
+
*
|
|
22
|
+
* if (!session) {
|
|
23
|
+
* redirect('/login');
|
|
24
|
+
* }
|
|
25
|
+
*
|
|
26
|
+
* return <div>Hello {session.user.email}</div>;
|
|
27
|
+
* }
|
|
28
|
+
*/
|
|
29
|
+
export declare function getServerSession(options: DailyServerClientOptions, cookieStore: CookieMethods): Promise<ServerSessionResult>;
|
|
30
|
+
/**
|
|
31
|
+
* Get session or throw - useful when you expect the user to be authenticated
|
|
32
|
+
*
|
|
33
|
+
* @throws Error if not authenticated
|
|
34
|
+
*/
|
|
35
|
+
export declare function requireServerSession(options: DailyServerClientOptions, cookieStore: CookieMethods): Promise<ServerAuthContext>;
|
|
36
|
+
/**
|
|
37
|
+
* Check if user is authenticated without fetching full session
|
|
38
|
+
*/
|
|
39
|
+
export declare function isAuthenticated(options: DailyServerClientOptions, cookieStore: CookieMethods): Promise<boolean>;
|
|
40
|
+
//# sourceMappingURL=session.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../src/nextjs/session.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EACV,iBAAiB,EACjB,mBAAmB,EACnB,wBAAwB,EACxB,aAAa,EACd,MAAM,YAAY,CAAC;AAIpB;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAsB,gBAAgB,CACpC,OAAO,EAAE,wBAAwB,EACjC,WAAW,EAAE,aAAa,GACzB,OAAO,CAAC,mBAAmB,CAAC,CA6B9B;AAED;;;;GAIG;AACH,wBAAsB,oBAAoB,CACxC,OAAO,EAAE,wBAAwB,EACjC,WAAW,EAAE,aAAa,GACzB,OAAO,CAAC,iBAAiB,CAAC,CAQ5B;AAED;;GAEG;AACH,wBAAsB,eAAe,CACnC,OAAO,EAAE,wBAAwB,EACjC,WAAW,EAAE,aAAa,GACzB,OAAO,CAAC,OAAO,CAAC,CAIlB"}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @daily/auth/nextjs Session
|
|
4
|
+
* Server-side session retrieval for Next.js
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.getServerSession = getServerSession;
|
|
8
|
+
exports.requireServerSession = requireServerSession;
|
|
9
|
+
exports.isAuthenticated = isAuthenticated;
|
|
10
|
+
const supabase_js_1 = require("@supabase/supabase-js");
|
|
11
|
+
const server_js_1 = require("./server.js");
|
|
12
|
+
/**
|
|
13
|
+
* Get the current user session in a server component or route handler
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* // In a server component
|
|
17
|
+
* import { cookies } from 'next/headers';
|
|
18
|
+
* import { getServerSession } from '@daily/auth/nextjs';
|
|
19
|
+
*
|
|
20
|
+
* export default async function Page() {
|
|
21
|
+
* const cookieStore = await cookies();
|
|
22
|
+
* const session = await getServerSession({
|
|
23
|
+
* supabaseUrl: process.env.NEXT_PUBLIC_SUPABASE_URL!,
|
|
24
|
+
* supabaseAnonKey: process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
|
|
25
|
+
* serviceKey: process.env.SUPABASE_SERVICE_ROLE_KEY,
|
|
26
|
+
* }, cookieStore);
|
|
27
|
+
*
|
|
28
|
+
* if (!session) {
|
|
29
|
+
* redirect('/login');
|
|
30
|
+
* }
|
|
31
|
+
*
|
|
32
|
+
* return <div>Hello {session.user.email}</div>;
|
|
33
|
+
* }
|
|
34
|
+
*/
|
|
35
|
+
async function getServerSession(options, cookieStore) {
|
|
36
|
+
const supabase = (0, server_js_1.createDailyServerClient)(options, cookieStore);
|
|
37
|
+
// Get user (validates JWT server-side)
|
|
38
|
+
const { data: { user }, error: userError } = await supabase.auth.getUser();
|
|
39
|
+
if (userError || !user) {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
// Get session for token info
|
|
43
|
+
const { data: { session }, error: sessionError } = await supabase.auth.getSession();
|
|
44
|
+
if (sessionError || !session) {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
// Fetch workspaces if service key provided
|
|
48
|
+
let workspaces = [];
|
|
49
|
+
if (options.serviceKey) {
|
|
50
|
+
workspaces = await fetchUserWorkspaces(options, user.id);
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
user,
|
|
54
|
+
session,
|
|
55
|
+
workspaces,
|
|
56
|
+
workspace: workspaces[0] || null,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Get session or throw - useful when you expect the user to be authenticated
|
|
61
|
+
*
|
|
62
|
+
* @throws Error if not authenticated
|
|
63
|
+
*/
|
|
64
|
+
async function requireServerSession(options, cookieStore) {
|
|
65
|
+
const session = await getServerSession(options, cookieStore);
|
|
66
|
+
if (!session) {
|
|
67
|
+
throw new Error('Not authenticated');
|
|
68
|
+
}
|
|
69
|
+
return session;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Check if user is authenticated without fetching full session
|
|
73
|
+
*/
|
|
74
|
+
async function isAuthenticated(options, cookieStore) {
|
|
75
|
+
const supabase = (0, server_js_1.createDailyServerClient)(options, cookieStore);
|
|
76
|
+
const { data: { user }, error } = await supabase.auth.getUser();
|
|
77
|
+
return !error && !!user;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Fetch user's workspaces using admin client
|
|
81
|
+
*/
|
|
82
|
+
async function fetchUserWorkspaces(options, userId) {
|
|
83
|
+
if (!options.serviceKey) {
|
|
84
|
+
return [];
|
|
85
|
+
}
|
|
86
|
+
const adminClient = (0, supabase_js_1.createClient)(options.supabaseUrl, options.serviceKey, {
|
|
87
|
+
auth: { autoRefreshToken: false, persistSession: false },
|
|
88
|
+
});
|
|
89
|
+
try {
|
|
90
|
+
const { data, error } = await adminClient
|
|
91
|
+
.from('workspace_members')
|
|
92
|
+
.select(`
|
|
93
|
+
role,
|
|
94
|
+
workspace:workspaces (
|
|
95
|
+
id,
|
|
96
|
+
name,
|
|
97
|
+
slug
|
|
98
|
+
)
|
|
99
|
+
`)
|
|
100
|
+
.eq('user_id', userId)
|
|
101
|
+
.order('created_at', { ascending: true });
|
|
102
|
+
if (error || !data) {
|
|
103
|
+
return [];
|
|
104
|
+
}
|
|
105
|
+
return data
|
|
106
|
+
.filter((row) => row.workspace)
|
|
107
|
+
.map((row) => {
|
|
108
|
+
const ws = row.workspace;
|
|
109
|
+
return {
|
|
110
|
+
id: ws.id,
|
|
111
|
+
name: ws.name,
|
|
112
|
+
slug: ws.slug,
|
|
113
|
+
role: row.role,
|
|
114
|
+
};
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
catch {
|
|
118
|
+
return [];
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
//# sourceMappingURL=session.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session.js","sourceRoot":"","sources":["../../src/nextjs/session.ts"],"names":[],"mappings":";AAAA;;;GAGG;;AAmCH,4CAgCC;AAOD,oDAWC;AAKD,0CAOC;AA/FD,uDAA0E;AAQ1E,2CAAsD;AAEtD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACI,KAAK,UAAU,gBAAgB,CACpC,OAAiC,EACjC,WAA0B;IAE1B,MAAM,QAAQ,GAAG,IAAA,mCAAuB,EAAC,OAAO,EAAE,WAAW,CAAC,CAAC;IAE/D,uCAAuC;IACvC,MAAM,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,GAAG,MAAM,QAAQ,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;IAE3E,IAAI,SAAS,IAAI,CAAC,IAAI,EAAE,CAAC;QACvB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,6BAA6B;IAC7B,MAAM,EAAE,IAAI,EAAE,EAAE,OAAO,EAAE,EAAE,KAAK,EAAE,YAAY,EAAE,GAAG,MAAM,QAAQ,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC;IAEpF,IAAI,YAAY,IAAI,CAAC,OAAO,EAAE,CAAC;QAC7B,OAAO,IAAI,CAAC;IACd,CAAC;IAED,2CAA2C;IAC3C,IAAI,UAAU,GAAoB,EAAE,CAAC;IACrC,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;QACvB,UAAU,GAAG,MAAM,mBAAmB,CAAC,OAAO,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC;IAC3D,CAAC;IAED,OAAO;QACL,IAAI;QACJ,OAAO;QACP,UAAU;QACV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AAS,EAAE,IAAI,EAAE,CAAC,CAAC;QAE5C,IAAI,KAAK,IAAI,CAAC,IAAI,EAAE,CAAC;YACnB,OAAO,EAAE,CAAC;QACZ,CAAC;QAED,OAAO,IAAI;aACR,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,SAAS,CAAC;aAC9B,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE;YACX,MAAM,EAAE,GAAG,GAAG,CAAC,SAAkE,CAAC;YAClF,OAAO;gBACL,EAAE,EAAE,EAAE,CAAC,EAAE;gBACT,IAAI,EAAE,EAAE,CAAC,IAAI;gBACb,IAAI,EAAE,EAAE,CAAC,IAAI;gBACb,IAAI,EAAE,GAAG,CAAC,IAA6B;aACxC,CAAC;QACJ,CAAC,CAAC,CAAC;IACP,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,CAAC;IACZ,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @daily/auth/nextjs Types
|
|
3
|
+
* Next.js SSR authentication types
|
|
4
|
+
*/
|
|
5
|
+
import type { User, Session, SupabaseClient } from '@supabase/supabase-js';
|
|
6
|
+
import type { WorkspaceInfo } from '../types.js';
|
|
7
|
+
/**
|
|
8
|
+
* Auth context available in server components and route handlers
|
|
9
|
+
*/
|
|
10
|
+
export interface ServerAuthContext {
|
|
11
|
+
user: User;
|
|
12
|
+
session: Session;
|
|
13
|
+
workspaces: WorkspaceInfo[];
|
|
14
|
+
/** Primary workspace (first in list) */
|
|
15
|
+
workspace: WorkspaceInfo | null;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Result from getServerSession - may be null if not authenticated
|
|
19
|
+
*/
|
|
20
|
+
export type ServerSessionResult = ServerAuthContext | null;
|
|
21
|
+
export interface DailyServerClientOptions {
|
|
22
|
+
supabaseUrl: string;
|
|
23
|
+
supabaseAnonKey: string;
|
|
24
|
+
/** Service key for fetching workspaces (optional) */
|
|
25
|
+
serviceKey?: string;
|
|
26
|
+
}
|
|
27
|
+
export interface DailyMiddlewareOptions extends DailyServerClientOptions {
|
|
28
|
+
/** Routes that don't require authentication (supports wildcards) */
|
|
29
|
+
publicPaths?: string[];
|
|
30
|
+
/** URL to redirect unauthenticated users */
|
|
31
|
+
loginUrl?: string;
|
|
32
|
+
/** URL to redirect after login (default: original URL) */
|
|
33
|
+
afterLoginUrl?: string;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Authenticated route handler function
|
|
37
|
+
*/
|
|
38
|
+
export type AuthenticatedHandler<T = Response> = (request: Request, context: ServerAuthContext) => Promise<T> | T;
|
|
39
|
+
/**
|
|
40
|
+
* Options for withAuth wrapper
|
|
41
|
+
*/
|
|
42
|
+
export interface WithAuthOptions {
|
|
43
|
+
/** Custom unauthorized response (default: 401 JSON) */
|
|
44
|
+
onUnauthorized?: (request: Request) => Response | Promise<Response>;
|
|
45
|
+
}
|
|
46
|
+
export interface CookieOptions {
|
|
47
|
+
name: string;
|
|
48
|
+
value: string;
|
|
49
|
+
maxAge?: number;
|
|
50
|
+
path?: string;
|
|
51
|
+
domain?: string;
|
|
52
|
+
secure?: boolean;
|
|
53
|
+
httpOnly?: boolean;
|
|
54
|
+
sameSite?: 'strict' | 'lax' | 'none';
|
|
55
|
+
}
|
|
56
|
+
export interface CookieMethods {
|
|
57
|
+
get(name: string): {
|
|
58
|
+
name: string;
|
|
59
|
+
value: string;
|
|
60
|
+
} | undefined;
|
|
61
|
+
set(name: string, value: string, options?: Omit<CookieOptions, 'name' | 'value'>): void;
|
|
62
|
+
remove(name: string, options?: Omit<CookieOptions, 'name' | 'value' | 'maxAge'>): void;
|
|
63
|
+
}
|
|
64
|
+
export interface CreateClientResult {
|
|
65
|
+
supabase: SupabaseClient;
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"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AAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,QAAQ,GAAG,KAAK,GAAG,MAAM,CAAC;CACtC;AAED,MAAM,WAAW,aAAa;IAC5B,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,GAAG,SAAS,CAAC;IAC/D,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,IAAI,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,IAAI,CAAC;IACxF,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,IAAI,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,GAAG,QAAQ,CAAC,GAAG,IAAI,CAAC;CACxF;AAMD,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,cAAc,CAAC;CAC1B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/nextjs/types.ts"],"names":[],"mappings":";AAAA;;;GAGG"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dailyautomations/auth",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Unified SSO authentication for Daily applications",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -28,6 +28,10 @@
|
|
|
28
28
|
"./types": {
|
|
29
29
|
"types": "./dist/types.d.ts",
|
|
30
30
|
"default": "./dist/types.js"
|
|
31
|
+
},
|
|
32
|
+
"./nextjs": {
|
|
33
|
+
"types": "./dist/nextjs/index.d.ts",
|
|
34
|
+
"default": "./dist/nextjs/index.js"
|
|
31
35
|
}
|
|
32
36
|
},
|
|
33
37
|
"files": [
|
|
@@ -55,21 +59,31 @@
|
|
|
55
59
|
"@supabase/supabase-js": "^2.0.0"
|
|
56
60
|
},
|
|
57
61
|
"devDependencies": {
|
|
62
|
+
"@supabase/ssr": "^0.5.0",
|
|
58
63
|
"@types/node": "^20.11.0",
|
|
59
64
|
"@types/react": "^18.2.0",
|
|
60
65
|
"@typescript-eslint/eslint-plugin": "^6.19.0",
|
|
61
66
|
"@typescript-eslint/parser": "^6.19.0",
|
|
62
67
|
"eslint": "^8.56.0",
|
|
68
|
+
"next": "^14.0.0",
|
|
63
69
|
"typescript": "^5.3.3",
|
|
64
70
|
"vitest": "^1.2.0"
|
|
65
71
|
},
|
|
66
72
|
"peerDependencies": {
|
|
67
73
|
"@supabase/supabase-js": "^2.0.0",
|
|
74
|
+
"@supabase/ssr": "^0.5.0",
|
|
75
|
+
"next": ">=14.0.0",
|
|
68
76
|
"react": ">=18.0.0"
|
|
69
77
|
},
|
|
70
78
|
"peerDependenciesMeta": {
|
|
71
79
|
"react": {
|
|
72
80
|
"optional": true
|
|
81
|
+
},
|
|
82
|
+
"@supabase/ssr": {
|
|
83
|
+
"optional": true
|
|
84
|
+
},
|
|
85
|
+
"next": {
|
|
86
|
+
"optional": true
|
|
73
87
|
}
|
|
74
88
|
}
|
|
75
89
|
}
|