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
Empty file added .cursor/cursor.md
Empty file.
133 changes: 133 additions & 0 deletions docs/wallet-auth-flow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
# Wallet-Based Authentication Flow

## Overview

VolunChain now uses wallet-based authentication instead of traditional email/password authentication. This provides a more secure and decentralized approach to user identification.

## Registration Flow

### Endpoint: `POST /auth/register`

**Request Body:**

```json
{
"name": "John Doe",
"email": "[email protected]",
"walletAddress": "GXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
"profileType": "user", // or "project"
"lastName": "Doe", // optional, for users
"category": "environmental" // required for projects
}
```

**Response:**

```json
{
"success": true,
"message": "User registered successfully",
"userId": "uuid-here"
}
```

### Profile Types

1. **User Profile** (`profileType: "user"`)

- Requires: name, email, walletAddress
- Optional: lastName
- Auto-verified upon registration

2. **Project/Organization Profile** (`profileType: "project"`)
- Requires: name, email, walletAddress, category
- Auto-verified upon registration

Comment on lines +42 to +45
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Terminology drift: β€œproject” vs β€œorganization”. Pick one and use it consistently.

Docs mix β€œproject” (profileType value) with β€œorganization” (route names). The codebase uses Organization as the model and register.usecase returns β€œorganization”. Align terms across request/response, routes, and models.

Example (if choosing "organization"):

-2. **Project/Organization Profile** (`profileType: "project"`)
+2. **Organization Profile** (`profileType: "organization"`)
- - `/auth/organization-only` - Only accessible by organization profiles
+ - `/auth/organization-only` - Only accessible by organization profiles

And update request/response samples accordingly.

Also applies to: 87-89, 36-40

🧰 Tools
πŸͺ› LanguageTool

[grammar] ~42-~42: There might be a mistake here.
Context: ...ion Profile** (profileType: "project") - Requires: name, email, walletAddress, ca...

(QB_NEW_EN)


[grammar] ~43-~43: There might be a mistake here.
Context: ...es: name, email, walletAddress, category - Auto-verified upon registration ## Logi...

(QB_NEW_EN)

πŸ€– Prompt for AI Agents
In docs/wallet-auth-flow.md around lines 42-45 (and also review lines 36-40 and
87-89), the doc mixes β€œproject” and β€œorganization”; pick one term (e.g.,
"organization") and make it consistent: change the profileType example value
from "project" to "organization", update the heading and bullet text to say
Organization, update all request/response samples and route names shown in the
doc to use "organization" (and not "project"), and ensure any returned type
strings mentioned (e.g., register.usecase outputs) use the chosen term; search
the file for any remaining occurrences of "project" and replace or reconcile
them to match the chosen terminology.

## Login Flow

### Endpoint: `POST /auth/login`

**Request Body:**

```json
{
"walletAddress": "GXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
}
```

**Response:**

```json
{
"success": true,
"message": "Login successful",
"token": "jwt-token-here",
"user": {
"id": "uuid-here",
"name": "John Doe",
"email": "[email protected]",
"wallet": "GXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
"profileType": "user"
}
}
```

## Protected Routes

### Authentication Middleware

All protected routes require a valid JWT token in the Authorization header:

```
Authorization: Bearer <jwt-token>
```

### Profile-Specific Routes

- `/auth/user-only` - Only accessible by user profiles
- `/auth/organization-only` - Only accessible by organization profiles
- `/auth/profile` - Accessible by both profile types

## Security Features

1. **Wallet Address Validation**: Ensures wallet addresses are valid Stellar addresses (56 characters)
2. **Unique Wallet Constraint**: Each wallet address can only be registered once
3. **JWT Tokens**: Secure token-based authentication with 24-hour expiration
4. **Auto-Verification**: All wallet-based registrations are automatically verified

## Error Handling

### Common Error Responses

**Wallet Address Not Found:**

```json
{
"success": false,
"message": "Wallet address not found"
}
```

**Wallet Address Already Registered:**

```json
{
"success": false,
"message": "Wallet address already registered"
}
```

**Invalid Token:**

```json
{
"success": false,
"message": "Invalid or expired token"
}
```

## Migration Notes

- Password fields have been removed from User and Organization models
- All existing authentication logic has been updated to use wallet-based auth
- Email verification is no longer required for wallet-based registrations
Loading