Make sure to add localhost to the authorized origins
defaultTheme: default theme lets you change the theme of your sign-in button, currently, we have only light mode but dark mode is going to be live soon.
eventsCallbacks: This allows you to perform certain actions when the user signs out or auth is successful.
I’ve also added a styles import from the neynar react package here which is needed for the styles of the sign-in button.
Now, let’s create a header component where we can add the sign-in with Neynar button.
So, create a new components/Header.tsx file and add the following:
Here, we are using the NeynarFeedList component to show the trending casts if the user is not signed in, but, if they are signed in we show the following feed based on their fid.
Now, let’s also show the list of channels that the user is following.
To get the list of channels that a user is following we’ll use the neynar APIs. So, let’s first initialise the client in a new lib/neynarClient.ts file like this:
Here, we are now fetching the list of channels that the user follows and creating links with the name of the channel. These link to another page which we are yet to build but you should be able to see the list of channels now!
Now, let’s build out the channel page as well which will show the feed of a specific channel.
Create a new channel/[channelId]/page.tsx file in the app folder and add the following:
Here, you can see that we are importing the component from a @/components/Neynar file and not the package directly because it is a client component. So, create a new components/Neynar.tsx file and add the following:
This will filter the feed based on the channelId and show only the casts made in that channel. If you go ahead and click on one of the channels you’ll be able to see something like this:
Here, I am first resolving the username in the path to get the user object which can be later used to get the fid of the user. Then, we are displaying the ProfileCard and the FeedList filtered based on the user’s fid. If you go to /profile/username then you’ll be able to see the user’s profile!
In this tutorial, we successfully built a Farcaster client with Next.js and the Neynar React SDK. Along the way, we covered essential features such as user authentication, creating feeds, fetching channels, and building user profiles. These steps give you a solid foundation to further enhance your client by adding more advanced features or customizing it to meet your specific needs.
To explore the full implementation, visit the GitHub repository. If you have any questions or want to share your progress, reach out to us on warpcast or Telegram.