npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

better-auth-social

v1.2.0

Published

A social network plugin for Better Auth with friends, friend requests, chat, and group chat features.

Downloads

297

Readme

Better Auth Social Network Plugin

Better-Auth plugin to add social features to your app: friends, friend requests, private chat, group chats, blocking, and a feed (posts).

Frontend CI Node.js Package Npm download Npm version

Installation

pnpm add better-auth-social
# or
npm install better-auth-social

Configuration

import { socialNetwork } from "better-auth-social";
import { betterAuth } from "better-auth";

const auth = betterAuth({
  database: { /* your adapter */ },
  plugins: [
    socialNetwork({
      maxGroupSize: 20,
      hooks: {
        onFriendRequestAccept: async (data) => console.log("Request accepted", data),
      },
    }),
  ],
});

Main features

Friends & friend requests

Manage relationships: send a request, accept or reject, list friends and sent/received requests.

Example

// Send a friend request
await auth.api.sendFriendRequest({
  body: { receiverId: "user-123" },
  headers,
});

// Accept
await auth.api.acceptFriendRequest({
  body: { requestId: "request-456" },
  headers,
});

| Method | Route | Body / Query | |--------|--------|---------------| | POST | /social/friend-request/send | { receiverId: string } | | POST | /social/friend-request/accept | { requestId: string } | | POST | /social/friend-request/reject | { requestId: string } | | GET | /social/friend-request/sent/list | — | | GET | /social/friend-request/received/list | — | | GET | /social/friends/list | ?page, limit (optional) | | POST | /social/friends/remove | { friendId: string } | | GET | /social/friends/is-friend | ?userId: string |


Private chat

1-to-1 conversations between friends: get or create a chat, list chats, send and delete messages.

Example

// Get or create a chat with a friend
const { chat } = await auth.api.getOrCreateChat({
  query: { friendId: "friend-id" },
  headers,
});

// Send a message
await auth.api.sendChatMessage({
  body: { chatId: chat.id, content: "Hello!" },
  headers,
});

| Method | Route | Body / Query | |--------|--------|---------------| | GET | /social/chat/get-or-create | ?friendId: string | | GET | /social/chat/list | ?page, limit (optional) | | GET | /social/chat-messages/list | ?chatId, page, limit | | POST | /social/chat-messages/send | { chatId: string, content: string } | | POST | /social/chat-messages/delete | { messageId: string } |


Group chat

Create groups, manage members, send group messages.

Example

// Create a group
const { groupChat } = await auth.api.createGroupChat({
  body: {
    name: "Team",
    description: "Project X",
    memberIds: ["user-1", "user-2"],
  },
  headers,
});

// Send a message in the group
await auth.api.sendGroupChatMessage({
  body: { groupChatId: groupChat.id, content: "Hi everyone" },
  headers,
});

| Method | Route | Body / Query | |--------|--------|---------------| | POST | /social/group-chat/create | { name: string, description?: string, memberIds: string[] } | | GET | /social/group-chat/list | ?page, limit (optional) | | GET | /social/group-chat/members | ?groupChatId: string | | POST | /social/group-chat/add-member | { groupChatId: string, userId: string } | | POST | /social/group-chat/remove-member | { groupChatId: string, userId: string } | | POST | /social/group-chat/leave | { groupChatId: string } | | POST | /social/group-chat/update | { groupChatId: string, name?: string, description?: string } | | GET | /social/group-chat/messages | ?groupChatId, page, limit | | POST | /social/group-chat/send-message | { groupChatId: string, content: string } | | POST | /social/group-chat/delete-message | { messageId: string } |


Blocked users

Block or unblock users and check if a user is blocked.

Example

await auth.api.blockUser({
  body: { userId: "user-to-block" },
  headers,
});

| Method | Route | Body / Query | |--------|--------|---------------| | GET | /social/blocked-users/list | — | | POST | /social/blocked-users/block | { userId: string } | | POST | /social/blocked-users/unblock | { userId: string } | | GET | /social/blocked-users/is-blocked | { userId: string } |


Feed (posts)

Create posts, like/unlike them, list a user’s posts.

Example

const { post } = await auth.api.createPost({
  body: { content: "My first post" },
  headers,
});

const { post } = await auth.api.likePost({
  body: {
    postId: post.id,
  },
  headers,
});

| Method | Route | Body / Query | |--------|--------|---------------| | GET | /social/posts/from-user | ?userId, page, limit | | POST | /social/posts/create | { content: string } (1–1000 characters) | | POST | /social/posts/delete | { postId: string } | | POST | /social/posts/like | { postId: string } | | POST | /social/posts/unlike | { postId: string } |


Hooks

A few hooks to react to events (all optional, async supported):

| Hook | Triggered when | |------|------------------| | onFriendRequestSend | A friend request is sent. Receives the created FriendRequest. | | onFriendRequestAccept | A friend request is accepted. Receives the updated FriendRequest. | | onGroupChatCreate | A group is created. Receives the GroupChat. | | onChatMessageSend | A message is sent in a private chat. Receives the ChatMessage. |

Other hooks exist (onFriendRemove, onChatCreate, onGroupChatJoin, onGroupChatLeave, etc.) — see the SocialNetworkHooks types in the code.

Example

socialNetwork({
  hooks: {
    onFriendRequestAccept: async (request) => {
      await sendNotification(request.receiverId, "New friend!");
    },
    onGroupChatCreate: async (groupChat) => {
      console.log("Group created:", groupChat.name);
    },
  },
});

Options

All plugin options:

| Option | Type | Default | Description | |--------|------|--------|-------------| | allowSelfFriendRequest | boolean | false | Allow users to send a friend request to themselves (useful for dev). | | allowMultipleGroupChatWithSamePerson | boolean | false | Allow multiple groups with the exact same members. | | allowAddingUnknownMembersToGroupChat | boolean | false | Allow adding users to a group who are not friends. | | messageDeletionRule | 'CANT_DELETE' \| 'SENDER_ONLY_VISIBLE' \| 'VISIBLE' | 'VISIBLE' | Who can delete a message and who sees the deleted message. | | deletedMessagePlaceholder | string \| (message) => Promise<string> | 'Message has been deleted' | Text (or function) shown for a deleted message. | | automaticBackFriend | boolean | false | Automatically create the reverse relationship when a request is accepted (if not already symmetric). | | maxGroupSize | number \| (() => Promise<number>) | 10 | Maximum number of members in a group (creator + members). | | hooks | SocialNetworkHooks | {} | Hooks called on events (see above). |


Client

The package exposes a client plugin for Better Auth:

import { socialNetworkClient } from "better-auth-social/client";
import { createAuthClient } from "better-auth/client";

const authClient = createAuthClient({
  baseURL: "http://localhost:3000",
  plugins: [socialNetworkClient()],
});

Routes are then called via authClient.fetch("/social/...", { method, body, query }) as in the examples above.


Database schema

The plugin registers the tables: friend_request, friend, chat, chat_message, group_chat, group_chat_member, group_chat_message, blocked_user, post, post_like.


License

MIT.