This is a boilerplate project for a Next.js 14 app using TypeScript, Tailwind CSS, Shadcn UI, Prisma, and Postgres, React Table, React Query. It includes features such as login, user management, user roles, user permissions, user profile, forgot password, reset password, nodemailer and more.
To use this boilerplate, clone the repository and install the dependencies:
git clone https://github.com/ahmedibra28/NEXTjs-boilerplate.git
cd NEXTjs-boilerplate
npm install
Create a .env.local
file in the root directory of the project with the following variables:
DATABASE_URL=postgres://user:password@localhost:5432/db_name
SMTP_SERVER=smtp.host.com
SMTP_PORT=465
[email protected]
SMTP_KEY=password
Make sure to replace user
, password
, and db_name
with your own Postgres credentials, and smtp.host.com
, [email protected]
, and password
with your own SMTP credentials.
Creating a blank migration for Custom function to the PostgreSQL instance using:
npx prisma migrate dev --create-only
You can name this migration 'nanoid'. Open the file created by the migration and paste the nanoid function
CREATE EXTENSION IF NOT EXISTS pgcrypto;
CREATE OR REPLACE FUNCTION nanoid(size int DEFAULT 21)
RETURNS text AS $$
DECLARE
id text := '';
i int := 0;
urlAlphabet char(64) := 'ModuleSymbhasOwnPr-0123456789ABCDEFGHNRVfgctiUvz_KqYTJkLxpZXIjQW';
bytes bytea := gen_random_bytes(size);
byte int;
pos int;
BEGIN
WHILE i < size LOOP
byte := get_byte(bytes, i);
pos := (byte & 63) + 1; -- + 1 because substr starts at 1 for some reason
id := id || substr(urlAlphabet, pos, 1);
i = i + 1;
END LOOP;
RETURN id;
END
$$ LANGUAGE PLPGSQL STABLE;
Then you can run this migration using:
npx prisma migrate dev
To start the development server, run:
npm run dev
To seed data, make a GET request to http://localhost:3000/api/seeds?secret=ts&option=reset
in your browser or with a tool like Postman. This will create default user roles and permissions and create a default admin user with the email [email protected]
and password 123456
.
Contributions are welcome! Feel free to open an issue or submit a pull request.
This project is licensed under the MIT License.