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"
Copy link

Choose a reason for hiding this comment

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

πŸ› οΈ Refactor suggestion

Inconsistent profileType terminology between interface and documentation.

The documentation shows "profileType": "user" and "profileType": "project" in the registration examples, but the domain interface IRegisterRequest uses "user" | "project" while IProfile uses "user" | "organization". This mismatch could lead to confusion.

Standardize the terminology across the system. Based on the domain interface patterns, consider updating the documentation to use consistent terminology:

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

Also applies to: 38-38

"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

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