File tree Expand file tree Collapse file tree 2 files changed +67
-0
lines changed Expand file tree Collapse file tree 2 files changed +67
-0
lines changed Original file line number Diff line number Diff line change
1
+ "use server" ;
2
+
3
+ import { db } from "@cap/database" ;
4
+ import { getCurrentUser } from "@cap/database/auth/session" ;
5
+ import { users } from "@cap/database/schema" ;
6
+ import { eq } from "drizzle-orm" ;
7
+
8
+ export async function promoteToPro ( ) {
9
+ "use server" ;
10
+
11
+ if ( process . env . NODE_ENV !== "development" )
12
+ throw new Error ( "promoteToPro can only be used in development" ) ;
13
+
14
+ const user = await getCurrentUser ( ) ;
15
+ if ( ! user ) throw new Error ( "No current user session" ) ;
16
+ await db ( )
17
+ . update ( users )
18
+ . set ( {
19
+ stripeCustomerId : "development" ,
20
+ stripeSubscriptionId : "development" ,
21
+ stripeSubscriptionStatus : "active" ,
22
+ } )
23
+ . where ( eq ( users . id , user . id ) ) ;
24
+ }
25
+
26
+ export async function demoteFromPro ( ) {
27
+ "use server" ;
28
+
29
+ if ( process . env . NODE_ENV !== "development" )
30
+ throw new Error ( "demoteFromPro can only be used in development" ) ;
31
+
32
+ const user = await getCurrentUser ( ) ;
33
+ if ( ! user ) throw new Error ( "No current user session" ) ;
34
+ await db ( )
35
+ . update ( users )
36
+ . set ( {
37
+ stripeCustomerId : null ,
38
+ stripeSubscriptionId : null ,
39
+ stripeSubscriptionStatus : null ,
40
+ } )
41
+ . where ( eq ( users . id , user . id ) ) ;
42
+ }
Original file line number Diff line number Diff line change @@ -71,6 +71,7 @@ export function ReactQueryProvider({
71
71
}
72
72
73
73
import { SessionProvider as NASessionProvider } from "next-auth/react" ;
74
+ import { demoteFromPro , promoteToPro } from "./devtoolsServer" ;
74
75
import { featureFlags , useFeatureFlags } from "./features" ;
75
76
76
77
export function SessionProvider ( { children } : PropsWithChildren ) {
@@ -122,6 +123,30 @@ function CapDevtools() {
122
123
< span > Enable Upload Progress UI</ span >
123
124
</ label >
124
125
</ div >
126
+ < div className = "space-y-2" >
127
+ < h1 className = "text-lg font-semibold" > Cap Pro</ h1 >
128
+ < p className = "text-xs text-muted-foreground" >
129
+ Toggle the current user's Pro status (dev only)
130
+ </ p >
131
+ < div className = "flex items-center space-x-2" >
132
+ < form action = { promoteToPro } >
133
+ < button
134
+ type = "submit"
135
+ className = "rounded bg-green-600 px-2 py-1 text-xs font-medium text-white hover:bg-green-700"
136
+ >
137
+ Promote to Pro
138
+ </ button >
139
+ </ form >
140
+ < form action = { demoteFromPro } >
141
+ < button
142
+ type = "submit"
143
+ className = "rounded bg-red-600 px-2 py-1 text-xs font-medium text-white hover:bg-red-700"
144
+ >
145
+ Demote from Pro
146
+ </ button >
147
+ </ form >
148
+ </ div >
149
+ </ div >
125
150
</ div >
126
151
) ;
127
152
}
You can’t perform that action at this time.
0 commit comments