Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ yarn-debug.log*
yarn-error.log*

# Uncomment to ignore lockfiles:
package-lock.json
yarn.lock
.pnpm-debug.log
.pnpmfile.cjs

Expand All @@ -30,6 +28,9 @@ jspm_packages/
/local-*.env
.env.docker

# SQLite database
*.db

# Build outputs
dist/
build/
Expand Down
55 changes: 53 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,53 @@
# Shipyard-Interns
Tasks submission and template respository.
# Shipyard Internship Task — Authentication & Authorization

**Candidate:** Aflaha A
**Task:** Authentication & Authorization (Task 2)
**Stack:** Next.js · Express.js · SQLite

---

## Overview

JWT-based authentication with role-based access control (RBAC). Users are assigned roles (`dev`, `lead`, `admin`) at registration. Project routes are protected — only authenticated users can access them, and only owners or admins can update or delete.

## Project Structure

```
├── backend/ # Express.js API
├── frontend/ # Next.js UI
└── README.md
```

## Quick Start

### Backend
```bash
cd backend
npm install
cp .env.example .env # set your JWT_SECRET
npm run seed # create sample users & projects
npm run dev # runs on http://localhost:5000
```

### Frontend
```bash
cd frontend
npm install
# create .env.local with: NEXT_PUBLIC_API_URL=http://localhost:5000/api
npm run dev # runs on http://localhost:3000
```

## Sample Accounts

| Email | Password | Role |
|---|---|---|
| admin@shipyard.dev | admin123 | admin |
| lead@shipyard.dev | lead123 | lead |
| dev@shipyard.dev | dev123 | dev |

## Running Tests

```bash
cd backend
npm test # 12 tests — auth + project endpoints
```
3 changes: 3 additions & 0 deletions backend/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
PORT=5000
JWT_SECRET=your_jwt_secret_here
DB_PATH=./database/database.db
29 changes: 29 additions & 0 deletions backend/database/seed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require("dotenv").config({ path: require("path").resolve(__dirname, "../.env") });
const bcrypt = require("bcryptjs");
const { User, Project, syncDB } = require("../src/models");

const seed = async () => {
await syncDB();

await User.destroy({ truncate: true });
await Project.destroy({ truncate: true });

const users = await User.bulkCreate([
{ name: "Alice Admin", email: "admin@shipyard.dev", password: bcrypt.hashSync("admin123", 10), role: "admin" },
{ name: "Leo Lead", email: "lead@shipyard.dev", password: bcrypt.hashSync("lead123", 10), role: "lead" },
{ name: "Dev Dana", email: "dev@shipyard.dev", password: bcrypt.hashSync("dev123", 10), role: "dev" },
]);

const lead = users.find(u => u.role === "lead");
const dev = users.find(u => u.role === "dev");

await Project.bulkCreate([
{ name: "Alpha", description: "First project", status: "active", owner_id: lead.id },
{ name: "Beta", description: "Second project", status: "inactive", owner_id: dev.id },
]);

console.log("✅ Seed complete");
process.exit(0);
};

seed().catch(err => { console.error(err); process.exit(1); });
Loading