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
}
Comment on lines +18 to +21
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Unify terminology: use β€œorganization” instead of β€œproject” for profileType.

Keep consistent with API and schema.

-  "profileType": "user", // or "project"
+  "profileType": "user", // or "organization"
...
-2. **Project/Organization Profile** (`profileType: "project"`)
-   - Requires: name, email, walletAddress, category
+2. **Organization Profile** (`profileType: "organization"`)
+   - Requires: name, email, walletAddress, category

Also applies to: 34-45

πŸ€– Prompt for AI Agents
In docs/wallet-auth-flow.md around lines 18-21 (and also update occurrences in
lines 34-45), the README uses the term "project" for profileType; change all
references of "project" to "organization" to match API/schema. Update examples,
comments, and any related field names (e.g., category description) so they read
"profileType": "user" // or "organization", and adjust explanatory text to refer
to organizations consistently.

```

**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

## 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