Inspired by T3 stack and Jack Harrington video, this is a role-based auth todo app.
Auth
- DiscordRoles
- Admin and User, the admin can delete or update all todos, user can manipulate only his todos.User and Admin panel
- each user has dedicated panel with actions
Next.js
13 app dirtRPC
Drizzle
ORM with SQLiteNext-Auth
Discord ProviderUI
Shadcn UIRoles
Admin and User
First, git clone the repository and install dependencies
npm install
# or
yarn
Add .env file to the root of the app, and fill env variables
DISCORD_CLIENT_ID=
DISCORD_CLIENT_SECRET=
NEXTAUTH_URL=http://localhost:3000
NEXTAUTH_SECRET=
for more details about setting env variables check:
Then run the database generation command:
yarn drizzle-kit generate:sqlite
And run the development server
npm run dev
# or
yarn dev
Open http://localhost:3000 with your browser to see the result.
for role change in development env use drizzle studio:
yarn drizzle-kit studio
navigate to provided URL from CLI, select the user
table on the UI, select the user, and change role to either ADMIN or USER
'use client'
import { trpc } from "@/app/_trpc/client";
function ClientComponent(){
const { data } = trpc.todo.getUserTodos.useQuery()
return (
...
)
}
import { serverClient } from "@/app/_trpc/serverClient";
async function ServerComponent() {
const trpcClient = await serverClient();
const data = await trpcClient.todo.getUserTodos();
return (
...
)
}
located in src/server/routers/root.ts
todoRouter
- used for todo CRUD operations, with middleware protections and payload validation
userRouter
- not used, added just for example
located in src/server/trpc.ts
publicProcedure
- no restriction
protectedProcedure
- requires from user to be authenticated
protectedAdminProcedure
- requires from user to be authenticated AND have an admin role
To learn more about Next.js, take a look at the following resources:
- Next.js Documentation
- Learn Next.js
- tRPC Documentation
- Drizzle Documentation
- Next-Auth Documentation
- Shadcn UI
Coming soon
Coming Soon