celo-poll/FARCASTER_EXISTING_ACCOUNTS.md
2025-12-08 16:31:30 +03:00

287 lines
5.4 KiB
Markdown

# โœ… Use Existing Farcaster Accounts
## ๐ŸŽฏ No Registration Needed!
PollCelo users **already have Farcaster accounts** because they're using Warpcast. We just need to access their existing FID.
---
## ๐Ÿ’ก How It Works
### Frame SDK Provides Everything
```typescript
import sdk from '@farcaster/frame-sdk'
// Get user's existing Farcaster account
const context = await sdk.context
const fid = context.user.fid // Their FID
const username = context.user.username // Their username
const pfp = context.user.pfpUrl // Their profile pic
```
**No registration needed!**
**No $5 fee!**
**Users already authenticated!**
---
## ๐Ÿš€ Updated Implementation
### Remove Registration Flow
```typescript
// โŒ OLD: Force users to register
router.push('/register')
// โœ… NEW: Use their existing account
const context = await sdk.context
const fid = context.user.fid
// Ready to vote!
```
### Simple Auth Check
```typescript
// app/page.tsx or any protected page
useEffect(() => {
const checkAuth = async () => {
const context = await sdk.context
if (!context?.user?.fid) {
// User not in Warpcast - show message
setError('Please open in Warpcast app')
return
}
// User authenticated, ready to use
setFid(context.user.fid)
}
checkAuth()
}, [])
```
---
## ๐Ÿ“Š What Users Have
When users open PollCelo in Warpcast, they already have:
- โœ… Farcaster ID (FID)
- โœ… Username (@username)
- โœ… Profile picture
- โœ… Account keys (managed by Warpcast)
- โœ… Authentication
**Cost to user:** $0
**Setup time:** 0 seconds
---
## ๐Ÿ”ง Updated File Structure
### Remove These (Not Needed)
```
โŒ lib/farcaster/register.ts
โŒ lib/farcaster/register-app.ts
โŒ lib/farcaster/add-key.ts
โŒ app/api/farcaster/register/route.ts
โŒ app/api/farcaster/add-key/route.ts
โŒ app/register/page.tsx
โŒ scripts/register-app.ts
```
### Keep These (Useful)
```
โœ… lib/farcaster/username.ts # Lookup users
โœ… app/api/farcaster/username/route.ts # Username API
โœ… components/UsernameSearch.tsx # Search component
```
---
## ๐Ÿ’ฐ Cost Comparison
| Method | User Cost | App Cost | Setup Time |
|--------|-----------|----------|------------|
| โŒ New Registration | $5 | $0 | 30 seconds |
| โœ… Existing Account | $0 | $0 | 0 seconds |
---
## ๐ŸŽฏ User Flow
### Old (Bad)
```
User opens app
โ†“
"Create Farcaster account"
โ†“
Pay $5
โ†“
Wait 30 seconds
โ†“
Finally can vote
```
### New (Good)
```
User opens app in Warpcast
โ†“
Already authenticated
โ†“
Vote immediately! โœ…
```
---
## ๐Ÿ” Authentication
### Get User Info
```typescript
import sdk from '@farcaster/frame-sdk'
const context = await sdk.context
// User info
const fid = context.user.fid
const username = context.user.username
const displayName = context.user.displayName
const pfpUrl = context.user.pfpUrl
const bio = context.user.profile.bio
// Use in your app
await createVote(pollId, optionId, fid)
await createComment(pollId, content, fid)
```
### Check If Authenticated
```typescript
if (!context?.user?.fid) {
return (
<div className="text-center p-8">
<p className="text-white text-xl mb-4">
Please open PollCelo in Warpcast
</p>
<a
href="https://warpcast.com"
className="text-celo-green hover:underline"
>
Download Warpcast โ†’
</a>
</div>
)
}
```
---
## ๐ŸŽจ Updated UI
### Header Component
```typescript
// components/Header.tsx
import sdk from '@farcaster/frame-sdk'
export default function Header() {
const [user, setUser] = useState<any>(null)
useEffect(() => {
sdk.context.then(ctx => setUser(ctx.user))
}, [])
return (
<header>
{user && (
<div className="flex items-center gap-2">
<img src={user.pfpUrl} className="w-8 h-8 rounded-full" />
<span>@{user.username}</span>
<span className="text-gray-400">FID: {user.fid}</span>
</div>
)}
</header>
)
}
```
---
## โœ… Benefits
### For Users
- โœ… No registration
- โœ… No $5 fee
- โœ… Instant access
- โœ… Use existing identity
- โœ… No new keys to manage
### For You
- โœ… No registration code to maintain
- โœ… No app FID needed
- โœ… No OP Mainnet RPC needed
- โœ… No ETH for gas
- โœ… Simpler codebase
---
## ๐Ÿงน Cleanup Steps
### 1. Remove Registration Files
```bash
rm -rf lib/farcaster/register*.ts
rm -rf lib/farcaster/add-key.ts
rm -rf app/api/farcaster/register
rm -rf app/api/farcaster/add-key
rm -rf app/register
rm -rf scripts/register-app.ts
```
### 2. Remove Environment Variables
```bash
# Remove from .env.local
# โŒ OP_MAINNET_RPC_URL
# โŒ APP_PRIVATE_KEY
```
### 3. Update Dependencies
```bash
# Can remove if not using for other features
npm uninstall @farcaster/hub-nodejs @noble/ed25519
```
---
## ๐Ÿ“ Updated Documentation
### Remove These Docs
```
โŒ FARCASTER_REGISTRATION.md
โŒ FARCASTER_BUNDLER.md
โŒ FARCASTER_KEYS.md
โŒ FARCASTER_SETUP.md
โŒ FARCASTER_INTEGRATION.md
โŒ FARCASTER_FINAL.md
```
### Keep This
```
โœ… FARCASTER_EXISTING_ACCOUNTS.md (this file)
โœ… FARCASTER_USERNAME.md (username lookup)
```
---
## ๐ŸŽ‰ Summary
**Old Approach:**
- โŒ Users pay $5
- โŒ 30 second wait
- โŒ Complex implementation
- โŒ Maintenance burden
**New Approach:**
- โœ… Users pay $0
- โœ… Instant access
- โœ… Simple implementation
- โœ… Use Frame SDK
**PollCelo users already have Farcaster accounts - just use them! ๐Ÿš€**