next-workflow-builder 0.3.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.
@@ -0,0 +1,105 @@
1
+ import {
2
+ accounts,
3
+ db,
4
+ integrations,
5
+ sessions,
6
+ users,
7
+ verifications,
8
+ workflowExecutionLogs,
9
+ workflowExecutions,
10
+ workflowExecutionsRelations,
11
+ workflows
12
+ } from "./chunk-3MSAF2TH.js";
13
+
14
+ // src/server/auth/index.ts
15
+ import { betterAuth } from "better-auth";
16
+ import { drizzleAdapter } from "better-auth/adapters/drizzle";
17
+ import { anonymous } from "better-auth/plugins";
18
+ import { eq } from "drizzle-orm";
19
+
20
+ // src/server/auth/config-store.ts
21
+ function getAuthConfig() {
22
+ const authOptions = process.env.__NWB_AUTH_OPTIONS ? JSON.parse(process.env.__NWB_AUTH_OPTIONS) : void 0;
23
+ return {
24
+ hasRealProviders: Object.keys(authOptions?.socialProviders ?? {})?.length > 0,
25
+ authOptions
26
+ };
27
+ }
28
+
29
+ // src/server/auth/index.ts
30
+ var schema = {
31
+ user: users,
32
+ session: sessions,
33
+ account: accounts,
34
+ verification: verifications,
35
+ workflows,
36
+ workflowExecutions,
37
+ workflowExecutionLogs,
38
+ workflowExecutionsRelations
39
+ };
40
+ function getBaseURL() {
41
+ if (process.env.BETTER_AUTH_URL) {
42
+ return process.env.BETTER_AUTH_URL;
43
+ }
44
+ if (process.env.NEXT_PUBLIC_APP_URL) {
45
+ return process.env.NEXT_PUBLIC_APP_URL;
46
+ }
47
+ if (process.env.VERCEL_URL) {
48
+ return `https://${process.env.VERCEL_URL}`;
49
+ }
50
+ return "http://localhost:3000";
51
+ }
52
+ function buildAuth() {
53
+ const config = getAuthConfig();
54
+ const plugins = [
55
+ // Anonymous sessions: enabled only when NO real providers configured (zero-config default)
56
+ ...!config.hasRealProviders ? [
57
+ anonymous({
58
+ async onLinkAccount(data) {
59
+ const fromUserId = data.anonymousUser.user.id;
60
+ const toUserId = data.newUser.user.id;
61
+ console.log(
62
+ `[Anonymous Migration] Migrating from user ${fromUserId} to ${toUserId}`
63
+ );
64
+ try {
65
+ await db.update(workflows).set({ userId: toUserId }).where(eq(workflows.userId, fromUserId));
66
+ await db.update(workflowExecutions).set({ userId: toUserId }).where(eq(workflowExecutions.userId, fromUserId));
67
+ await db.update(integrations).set({ userId: toUserId }).where(eq(integrations.userId, fromUserId));
68
+ console.log(
69
+ `[Anonymous Migration] Successfully migrated data from ${fromUserId} to ${toUserId}`
70
+ );
71
+ } catch (error) {
72
+ console.error(
73
+ "[Anonymous Migration] Error migrating user data:",
74
+ error
75
+ );
76
+ throw error;
77
+ }
78
+ }
79
+ })
80
+ ] : []
81
+ ];
82
+ return betterAuth({
83
+ baseURL: getBaseURL(),
84
+ // always use internal baseURL
85
+ database: drizzleAdapter(db, {
86
+ // always use internal db
87
+ provider: "pg",
88
+ schema
89
+ }),
90
+ ...config.authOptions,
91
+ // user overrides (base layer)
92
+ plugins: [
93
+ ...plugins,
94
+ // built-in plugins
95
+ ...config.authOptions?.plugins ?? []
96
+ // user's additional plugins
97
+ ]
98
+ });
99
+ }
100
+ var auth = buildAuth();
101
+
102
+ export {
103
+ getAuthConfig,
104
+ auth
105
+ };