You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A node/express backend API template for getting started with a new project that includes authentication, permissions, and a database configured to
21
22
use [Supabase](https://supabase.io/) or a local/cloud Postgres database.
22
23
23
-
This comes pre-defined with a workspaces model that allows accounts (users) to create workspaces and invite other profiles (users presence within a workspace) to access the workspace (membership). see the [Permissions](#Permissions) section for more information on how permissions are defined.
24
+
This comes pre-defined with a workspaces model that allows accounts (users) to create workspaces and invite other profiles (users presence within a workspace) to access the workspace (membership). see the [Permissions](#permissions) section for more information on how permissions are defined.
24
25
25
26
The contents of a workspace is not defined in this template and can be customized to suit the needs of the project.
26
27
@@ -38,29 +39,51 @@ This project requires node.js to be installed. This project uses volta to manage
38
39
39
40
To install volta run the following command in the terminal.
40
41
41
-
```
42
+
```bash
42
43
curl https://get.volta.sh | bash
43
44
```
44
45
45
-
You will need a Postgres database to run this project. You can use Docker to run a Postgres database or use a service like [Supabase](https://supabase.com/).
46
+
You will need a Postgres database to run this project. You can use Docker to run a Postgres database or use a service like [Supabase](https://supabase.com/). The auth provider can be replaced with any other Auth providers eg Firebase, Auth0, Keycloak you just need to implement the authentication middleware to verify the token and decode the claims and modify the auth handlers to use your provider.
47
+
48
+
See the [Database](#database) section for more information on how to configure the database connection.
49
+
50
+
Authentication is handled by [Supabase](https://supabase.com/) and requires a Supabase account. You can sign up for a free account at [supabase.com](https://supabase.com/).
51
+
52
+
### Install PNPM
53
+
54
+
If using volta we can install corepack globally and let volta manage the binary, corepack will let us use the correct version of pnpm based on the `packageManager` field in the package.json file.
55
+
56
+
```bash
57
+
npm install --global corepack@latest
58
+
59
+
corepack enable pnpm
60
+
```
46
61
47
-
See the [Database](#Database) section for more information on how to configure the database connection.
62
+
see the [installation docs for pnpm](https://pnpm.io/installation) and the [corepack docs](https://github.com/nodejs/corepack)
63
+
for more information on how to install pnpm and corepack.
48
64
49
65
### ENV
50
66
51
67
Create a .env file in the root of the project and copy the contents of .env.example into it.
52
68
53
-
```
69
+
```bash
54
70
cp .env.example .env
55
71
```
56
72
57
73
see the section on [Deployment with DigitalOcean](#deployment-with-digitalocean) for more information on how to configure the environment variables for deployment in different environments (eg. development and production).
58
74
59
75
### Install dependencies
60
76
77
+
```bash
78
+
pnpm i
61
79
```
62
-
# install dependencies
63
-
npm i
80
+
81
+
### Setup the database
82
+
83
+
The first time setting up the database you will need to run the `migrate` command to create the database tables and apply the migrations.
84
+
85
+
```bash
86
+
pnpm run migrate
64
87
```
65
88
66
89
## Testing
@@ -80,9 +103,10 @@ You can install the supabase cli for local development.
80
103
81
104
## Database
82
105
83
-
You can view the database with `npx drizzle-kit studio` or `npm run studio`.
106
+
You can view the database with `pnpx drizzle-kit studio` or `pnpm run studio`.
84
107
85
108
You can spin up a local copy of the database and application with `docker-compose` but this is not required when using the Supabase db.
109
+
86
110
When using the supabase cli we can run a local copy of the db with `supabase start`.
87
111
88
112
### Developing locally with supabase
@@ -91,13 +115,13 @@ This will provide you with a connection string, you can update the local environ
Visit the Supabase dashboard: http://localhost:54323 and manage your database locally.
118
+
Visit the Supabase dashboard: http://localhost:54323 and manage your database locally. Note: It appears that the database name needs to be `postgres` to be able to work with the Supabase dashboard.
95
119
96
120
### Local Postgres with Docker
97
121
98
122
You can spin up a local database and application with `docker-compose` but this is not required when using the Supabase db or cli.
99
123
100
-
```
124
+
```bash
101
125
docker compose up -d
102
126
```
103
127
@@ -125,38 +149,52 @@ Note: If you are using a local database and running the application within docke
125
149
126
150
### Migrations
127
151
152
+
When running the migrations for the first time on a new database run:
153
+
154
+
```bash
155
+
pnpm run migrate
156
+
```
157
+
128
158
When the schema/model is changed make sure to create a new migration and run it against the db.
129
159
130
-
1. Create a new migration
160
+
### 1. Create a new migration
131
161
132
-
```
133
-
npm run migrate:create
162
+
```bash
163
+
pnpm run migrate:create
134
164
135
165
```
136
166
137
-
2. Run the migrations
167
+
### 2. Run the migrations
138
168
139
-
```
140
-
npm run migrate:up
169
+
```bash
170
+
# first run the migrations
171
+
pnpm run migrate:up
172
+
173
+
# then run
174
+
pnpm migrate:push
141
175
```
142
176
143
177
### Seeds
144
178
145
179
You can run the seeds to populate the database with initial data.
146
180
147
-
Before seeding the db make sure to run the migrations. If you want to populate the seeds with specific user email, password or id's related to the users created in Supabase. You can update the seeds in `./src/seeds/` with the required data and make sure to pass the `--supabase=true` flag to the seed command and it will create the users in Supabase and associate the id's with the db records.
181
+
Before seeding the db make sure to run the migrations. If you want to populate the seeds with specific user email, password or id's related to the users created in Supabase. You can update the seeds in `./src/seeds/` with the required data.
148
182
149
-
Note: If you are creating users with Supabase you will need to confirm the email addresses.
183
+
You will need to add these users to supabase auth and confirm the email addresses.
150
184
151
-
```
152
-
npm run seed
185
+
<!-- and make sure to pass the `--supabase=true` flag to the seed command and it will create the users in Supabase and associate the id's with the db records.
186
+
187
+
Note: If you are creating users with Supabase you will need to confirm the email addresses.-->
188
+
189
+
```bash
190
+
pnpm run seed
153
191
```
154
192
155
193
Be sure to update the seeds as new migrations are added.
0 commit comments