Get up and running with Gel and Next.js quickly. It includes a basic setup for authentication, Gel schema, and a UI to get you started.
This starter is designed to help you get up and running with Gel and Next.js quickly. It includes a basic setup for authentication, Gel schema, and a UI to get you started. Below you can find the steps to set up the project and start building your app as well as some ideas for extending it further.
This template includes:
.├── README.md├── app│ ├── auth│ ├── dashboard│ ├── favicon.ico│ ├── globals.css│ ├── layout.tsx│ └── page.tsx├── auth-setup.ts├── components/├── src/├── public/├── dbschema│ ├── default.gel│ └── migrations├── gel.toml├── gel.ts├── eslint.config.js├── next-env.d.ts├── next.config.js├── package.json├── password-auth-setup.ts├── pnpm-lock.yaml├── postcss.config.js├── tailwind.config.ts└── tsconfig.json
Directory structure:
app/
public/
components/
src/
dbschema/
gel.toml
gel.ts
auth-setup.ts
password-auth-setup.ts
eslint.config.js
next-env.d.ts
next.config.js
package.json
pnpm-lock.yaml
postcss.config.js
tailwind.config.ts
tsconfig.json
To get started with this template, you need to:
git clone https://github.com/geldata/nextjs-gel-auth-template.gitcd nextjs-gel-auth-templatepnpm i
You can also click the "Use this template" button to create a new repository based on this template.
You can just use
npx gel
This README will use
npx gel <command>
gel <command>
curl --proto '=https' --tlsv1.2 -sSf https://sh.gel.com | sh
For more installation options, see the Gel installation guide.
To run this project, you need to initialize a new Gel project. Run the following command:
npx gel project init
This template includes a script to set up Gel Auth. It defaults to email+password authentication. Run the following command:
pnpm auth:setup
This template includes a script to generate TypeScript types from the Gel schema. Run the following command:
pnpm generate:all
pnpm dev
Follow the instructions in the terminal to open the app in your browser.
To view the database in the Gel UI or make changes to the Gel Auth configuration, run:
npx gel ui
Click the sign up button in the top right corner to create an account. We're using the built-in authentication for this starter but you can implement a custom UI later.
Open the
dbschema/default.gel
Post
title
content
Item
type Item {# ...# Add your new fields here:required title: str;required content: str;}
Open the
app/dashboard/page.tsx
const items = await client.query<Props["items"][number]>(`select Item {id,name,created,updated,created_by: {name,}};`);
Open the Gel UI with the
npx gel ui
Sign out of your account and try to reset your password. Click the "Forgot Password" link on the login page and follow the instructions to reset your password. You should receive an email with a link to reset your password. To test it locally, you can use the Mailpit tool.
To set up the Mailpit tool, run the following command:
brew install mailpit
Or follow the instructions in the Mailpit docs.
Next, run the following command to start the Mailpit server:
mailpit
After that, you can open the Mailpit UI in your browser at
http://localhost:8025
To test the reset password flow with Mailpit, you need to update the SMTP settings in the Gel UI. Open the Gel UI with the
npx gel ui
localhost
1025
The remaining fields can be left empty.
Open the
components/AddItem.tsx
Try deleting an item that you don't own. You shouldn't be able to delete it. You can test this by creating a new item and then trying to delete it with a different account. As a next step you can conditionally render the delete button based on the user's permissions.
In the
app/auth/[...auth]/route.ts
In the
dbschema/default.gel
User
Item
using extension auth;
This line enables the Gel Auth extension, which provides built-in authentication and authorization features.
scalar type Role extending enum<admin, user>;global current_user := (assert_single((select Userfilter .identity = global ext::auth::ClientTokenIdentity)));type User {required identity: ext::auth::Identity;required name: str;email: str;userRole: Role {default := "user";};created: datetime {rewrite insert using (datetime_of_statement());}updated: datetime {rewrite insert using (datetime_of_statement());rewrite update using (datetime_of_statement());}}
This block defines the
Role
User
The
identity
User
ext::auth::Identity
The
global current_user
User
ext::auth::ClientTokenIdentity
The
userRole
The
created
updated
type Item {required name: str;required created_by: User {default := global current_user;}created: datetime {rewrite insert using (datetime_of_statement());}updated: datetime {rewrite insert using (datetime_of_statement());rewrite update using (datetime_of_statement());}access policy admin_has_full_accessallow allusing (global current_user.userRole ?= Role.admin);access policy creator_has_full_accessallow allusing (.created_by ?= global current_user);access policy others_read_onlyallow select, insert;}
This block defines the
Item
The
created_by
User
The
created
updated
The
access policy
Item
admin_has_full_access
creator_has_full_access
others_read_only
To learn more about Next.js, take a look at the following resources:
You can also check out the Gel documentation to learn more about Gel and Gel Auth.
Follow the deployment instructions in the Gel documentation to deploy your Next.js app to Gel Cloud and Vercel.
Get up and running with Gel and Next.js quickly. It includes a basic setup for authentication, Gel schema, and a UI to get you started.
This starter is designed to help you get up and running with Gel and Next.js quickly. It includes a basic setup for authentication, Gel schema, and a UI to get you started. Below you can find the steps to set up the project and start building your app as well as some ideas for extending it further.
This template includes:
.├── README.md├── app│ ├── auth│ ├── dashboard│ ├── favicon.ico│ ├── globals.css│ ├── layout.tsx│ └── page.tsx├── auth-setup.ts├── components/├── src/├── public/├── dbschema│ ├── default.gel│ └── migrations├── gel.toml├── gel.ts├── eslint.config.js├── next-env.d.ts├── next.config.js├── package.json├── password-auth-setup.ts├── pnpm-lock.yaml├── postcss.config.js├── tailwind.config.ts└── tsconfig.json
Directory structure:
app/
public/
components/
src/
dbschema/
gel.toml
gel.ts
auth-setup.ts
password-auth-setup.ts
eslint.config.js
next-env.d.ts
next.config.js
package.json
pnpm-lock.yaml
postcss.config.js
tailwind.config.ts
tsconfig.json
To get started with this template, you need to:
git clone https://github.com/geldata/nextjs-gel-auth-template.gitcd nextjs-gel-auth-templatepnpm i
You can also click the "Use this template" button to create a new repository based on this template.
You can just use
npx gel
This README will use
npx gel <command>
gel <command>
curl --proto '=https' --tlsv1.2 -sSf https://sh.gel.com | sh
For more installation options, see the Gel installation guide.
To run this project, you need to initialize a new Gel project. Run the following command:
npx gel project init
This template includes a script to set up Gel Auth. It defaults to email+password authentication. Run the following command:
pnpm auth:setup
This template includes a script to generate TypeScript types from the Gel schema. Run the following command:
pnpm generate:all
pnpm dev
Follow the instructions in the terminal to open the app in your browser.
To view the database in the Gel UI or make changes to the Gel Auth configuration, run:
npx gel ui
Click the sign up button in the top right corner to create an account. We're using the built-in authentication for this starter but you can implement a custom UI later.
Open the
dbschema/default.gel
Post
title
content
Item
type Item {# ...# Add your new fields here:required title: str;required content: str;}
Open the
app/dashboard/page.tsx
const items = await client.query<Props["items"][number]>(`select Item {id,name,created,updated,created_by: {name,}};`);
Open the Gel UI with the
npx gel ui
Sign out of your account and try to reset your password. Click the "Forgot Password" link on the login page and follow the instructions to reset your password. You should receive an email with a link to reset your password. To test it locally, you can use the Mailpit tool.
To set up the Mailpit tool, run the following command:
brew install mailpit
Or follow the instructions in the Mailpit docs.
Next, run the following command to start the Mailpit server:
mailpit
After that, you can open the Mailpit UI in your browser at
http://localhost:8025
To test the reset password flow with Mailpit, you need to update the SMTP settings in the Gel UI. Open the Gel UI with the
npx gel ui
localhost
1025
The remaining fields can be left empty.
Open the
components/AddItem.tsx
Try deleting an item that you don't own. You shouldn't be able to delete it. You can test this by creating a new item and then trying to delete it with a different account. As a next step you can conditionally render the delete button based on the user's permissions.
In the
app/auth/[...auth]/route.ts
In the
dbschema/default.gel
User
Item
using extension auth;
This line enables the Gel Auth extension, which provides built-in authentication and authorization features.
scalar type Role extending enum<admin, user>;global current_user := (assert_single((select Userfilter .identity = global ext::auth::ClientTokenIdentity)));type User {required identity: ext::auth::Identity;required name: str;email: str;userRole: Role {default := "user";};created: datetime {rewrite insert using (datetime_of_statement());}updated: datetime {rewrite insert using (datetime_of_statement());rewrite update using (datetime_of_statement());}}
This block defines the
Role
User
The
identity
User
ext::auth::Identity
The
global current_user
User
ext::auth::ClientTokenIdentity
The
userRole
The
created
updated
type Item {required name: str;required created_by: User {default := global current_user;}created: datetime {rewrite insert using (datetime_of_statement());}updated: datetime {rewrite insert using (datetime_of_statement());rewrite update using (datetime_of_statement());}access policy admin_has_full_accessallow allusing (global current_user.userRole ?= Role.admin);access policy creator_has_full_accessallow allusing (.created_by ?= global current_user);access policy others_read_onlyallow select, insert;}
This block defines the
Item
The
created_by
User
The
created
updated
The
access policy
Item
admin_has_full_access
creator_has_full_access
others_read_only
To learn more about Next.js, take a look at the following resources:
You can also check out the Gel documentation to learn more about Gel and Gel Auth.
Follow the deployment instructions in the Gel documentation to deploy your Next.js app to Gel Cloud and Vercel.