forked from wasp-lang/SaaS-Template-GPT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.wasp
179 lines (156 loc) Β· 5.18 KB
/
main.wasp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
app SaaSTemplate {
wasp: {
version: "^0.9.0"
},
title: "My SaaS App",
head: [
"<meta property='og:type' content='website' />",
"<meta property='og:url' content='https://mySaaSapp.com' />",
"<meta property='og:description' content='I made a SaaS App. Buy my stuff.' />",
"<meta property='og:image' content='src/client/static/image.png' />",
// put your google analytics script here, too!
],
// π Auth out of the box! https://wasp-lang.dev/docs/language/features#authentication--authorization
auth: {
userEntity: User,
externalAuthEntity: SocialLogin,
methods: {
google: { // Guide for setting up Auth via Google https://wasp-lang.dev/docs/integrations/google
getUserFieldsFn: import { getUserFields } from "@server/auth/google.js",
configFn: import { config } from "@server/auth/google.js",
},
},
onAuthFailedRedirectTo: "/",
},
db: {
system: PostgreSQL
},
server: {
setupFn: import serverSetup from "@server/serverSetup.js"
},
client: {
rootComponent: import App from "@client/App",
},
dependencies: [
("@headlessui/react", "1.7.13"),
("@tailwindcss/forms", "^0.5.3"),
("@tailwindcss/typography", "^0.5.7"),
("react-hook-form", "7.43.1"),
("react-icons", "4.8.0"),
("@sendgrid/mail", "7.7.0"),
("request-ip", "3.3.0"),
("@types/request-ip", "0.0.37"),
("node-fetch", "3.3.0"),
("react-hook-form", "7.43.1"),
("stripe", "11.15.0"),
],
}
/* π½ Wasp defines DB entities via Prisma Database Models:
* https://wasp-lang.dev/docs/language/features#entity
*/
entity User {=psl
id Int @id @default(autoincrement())
username String @unique
email String @unique
password String
stripeId String?
checkoutSessionId String?
hasPaid Boolean @default(false)
sendEmail Boolean @default(false)
datePaid DateTime?
credits Int @default(3)
relatedObject RelatedObject[]
externalAuthAssociations SocialLogin[]
psl=}
entity SocialLogin {=psl
id String @id @default(uuid())
provider String
providerId String
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
userId Int
createdAt DateTime @default(now())
@@unique([provider, providerId, userId])
psl=}
// This can be anything. In most cases, this will be your product
entity RelatedObject {=psl
id String @id @default(uuid())
content String
user User @relation(fields: [userId], references: [id])
userId Int
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
psl=}
/* π‘ These are the Wasp Routes (You can protect them easily w/ 'authRequired: true');
* https://wasp-lang.dev/docs/language/features#route
*/
route RootRoute { path: "/", to: MainPage }
page MainPage {
component: import Main from "@client/MainPage"
}
route LoginRoute { path: "/login", to: LoginPage }
page LoginPage {
component: import Login from "@client/Login"
}
route GptRoute { path: "/gpt", to: GptPage }
page GptPage {
component: import GptPage from "@client/GptPage"
}
route PricingRoute { path: "/pricing", to: PricingPage }
page PricingPage {
component: import Pricing from "@client/PricingPage"
}
route AccountRoute { path: "/account", to: AccountPage }
page AccountPage {
authRequired: true,
component: import Account from "@client/AccountPage"
}
route CheckoutRoute { path: "/checkout", to: CheckoutPage }
page CheckoutPage {
authRequired: true,
component: import Checkout from "@client/CheckoutPage"
}
/* β These are the Wasp Operations, which allow the client and server to interact:
* https://wasp-lang.dev/docs/language/features#queries-and-actions-aka-operations
*/
// π Actions aka Mutations
action generateGptResponse {
fn: import { generateGptResponse } from "@server/actions.js",
entities: [User, RelatedObject]
}
action stripePayment {
fn: import { stripePayment } from "@server/actions.js",
entities: [User]
}
// action stripeCreditsPayment {
// fn: import { stripeCreditsPayment } from "@server/actions.js",
// entities: [User]
// }
// action updateUser {
// fn: import { updateUser } from "@server/actions.js",
// entities: [User]
// }
// π Queries
query getRelatedObjects {
fn: import { getRelatedObjects } from "@server/queries.js",
entities: [User, RelatedObject]
}
/* π΅οΈββοΈ These are the Wasp Cron Jobs. Use them to set up recurring tasks and/or queues:
* https://wasp-lang.dev/docs/language/features#jobs
*/
job emailChecker {
executor: PgBoss,
perform: {
fn: import { checkAndQueueEmails } from "@server/workers/checkAndQueueEmails.js"
},
schedule: {
cron: "0 7 * * 1" // at 7:00 am every Monday
},
entities: [User]
}
job emailSender {
executor: PgBoss,
perform: {
fn: import { sendGrid } from "@server/workers/sendGrid.js"
},
entities: [User]
}