2025-12-08 16:31:30 +03:00

33 lines
672 B
TypeScript

import sdk from '@farcaster/frame-sdk'
export async function getCurrentUser() {
try {
const context = await sdk.context
if (!context?.user?.fid) {
return null
}
return {
fid: context.user.fid,
username: context.user.username,
displayName: context.user.displayName,
pfpUrl: context.user.pfpUrl,
bio: context.user.profile?.bio,
}
} catch (error) {
console.error('Failed to get user:', error)
return null
}
}
export async function requireAuth() {
const user = await getCurrentUser()
if (!user) {
throw new Error('Not authenticated. Please open in Warpcast.')
}
return user
}