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

@yusufstar07/sdk-client

v1.1.1

Published

SDK client for Multi-Auth Platform authentication

Readme

Multi-Auth Platform SDK Client

A fetch-based authentication client for Next.js and React applications. Supports both client-side and server-side rendering (SSR).

Installation

npm install @yusufstar07/sdk-client

Usage

Basic Setup

import { createSDKClient } from "@yusufstar07/sdk-client";

const sdk = createSDKClient({
    apiKey: process.env.NEXT_PUBLIC_API_KEY!, // Your API key
    baseUrl: process.env.NEXT_PUBLIC_API_URL!, // Your API base URL (e.g., http://localhost:3001)
});

Client-Side Usage (React)

"use client";

import { createSDKClient } from "@yusufstar07/sdk-client";
import { useState } from "react";

const sdk = createSDKClient({
    apiKey: process.env.NEXT_PUBLIC_API_KEY!,
    baseUrl: process.env.NEXT_PUBLIC_API_URL!,
});

export default function LoginPage() {
    const [email, setEmail] = useState("");
    const [password, setPassword] = useState("");

    const handleLogin = async () => {
        try {
            const response = await sdk.login({ email, password });
            console.log("Logged in:", response.user);
        } catch (error) {
            console.error("Login failed:", error);
        }
    };

    return (
        <form onSubmit={(e) => { e.preventDefault(); handleLogin(); }}>
            <input
                type="email"
                value={email}
                onChange={(e) => setEmail(e.target.value)}
                placeholder="Email"
            />
            <input
                type="password"
                value={password}
                onChange={(e) => setPassword(e.target.value)}
                placeholder="Password"
            />
            <button type="submit">Login</button>
        </form>
    );
}

Server-Side Usage (Next.js App Router)

// app/api/user/route.ts
import { createSDKClient, getAccessTokenFromCookieString } from "@yusufstar07/sdk-client";
import { cookies } from "next/headers";
import { NextResponse } from "next/server";

const sdk = createSDKClient({
    apiKey: process.env.API_KEY!,
    baseUrl: process.env.API_URL!,
});

export async function GET() {
    try {
        const cookieStore = await cookies();
        const cookieString = cookieStore.toString();
        const accessToken = getAccessTokenFromCookieString(cookieString);

        if (!accessToken) {
            return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
        }

        const response = await sdk.me(accessToken);
        return NextResponse.json(response);
    } catch (error: any) {
        return NextResponse.json(
            { error: error.error || "Failed to get user" },
            { status: error.status || 500 }
        );
    }
}

Server Component Usage

// app/profile/page.tsx
import { createSDKClient, getAccessTokenFromCookieString } from "@yusufstar07/sdk-client";
import { cookies } from "next/headers";
import { redirect } from "next/navigation";

const sdk = createSDKClient({
    apiKey: process.env.API_KEY!,
    baseUrl: process.env.API_URL!,
    fetch: fetch,
});

export default async function ProfilePage() {
    const cookieStore = await cookies();
    const cookieString = cookieStore.toString();
    const accessToken = getAccessTokenFromCookieString(cookieString);

    if (!accessToken) {
        redirect("/login");
    }

    try {
        const { user } = await sdk.me(accessToken);
        return (
            <div>
                <h1>Profile</h1>
                <p>Email: {user.email}</p>
                <p>Name: {user.name}</p>
            </div>
        );
    } catch (error) {
        redirect("/login");
    }
}

API Methods

register(data: RegisterRequest): Promise<RegisterResponse>

Register a new user.

const response = await sdk.register({
    email: "[email protected]",
    password: "password123",
    name: "John Doe", // Optional
});

login(data: LoginRequest): Promise<LoginResponse>

Login user and store tokens in cookies.

const response = await sdk.login({
    email: "[email protected]",
    password: "password123",
});

refresh(refreshToken?: string): Promise<RefreshResponse>

Refresh access token using refresh token.

const response = await sdk.refresh(); // Uses cookie if available
// or
const response = await sdk.refresh(customRefreshToken);

logout(accessToken?: string): Promise<LogoutResponse>

Logout user and clear tokens.

await sdk.logout(); // Uses cookie if available

me(accessToken?: string): Promise<MeResponse>

Get current authenticated user.

const response = await sdk.me(); // Uses cookie if available

isAuthenticated(): boolean

Check if user is authenticated (has access token in cookie).

if (sdk.isAuthenticated()) {
    // User is logged in
}

getToken(): string | null

Get current access token from cookie.

const token = sdk.getToken();

Configuration Options

interface SDKClientConfig {
    apiKey: string; // Required: Your API key
    baseUrl: string; // Required: API base URL
    cookieDomain?: string; // Optional: Cookie domain
    useCookies?: boolean; // Optional: Use cookies for token storage (default: true)
}

Error Handling

All methods throw SDKError objects:

try {
    await sdk.login({ email, password });
} catch (error: SDKError) {
    console.error(error.error); // Error message
    console.error(error.status); // HTTP status code
}

SSR Compatibility

The SDK is fully compatible with Next.js App Router and Server Components:

  1. Server Components: Use getAccessTokenFromCookieString() to get tokens from cookies
  2. API Routes: Use cookies() from next/headers to get cookie string
  3. Axios: SDK uses axios internally, which works seamlessly in both client and server environments

TypeScript Support

Full TypeScript support with exported types:

import type {
    SDKUser,
    RegisterRequest,
    LoginRequest,
    SDKError,
    SDKClientConfig,
} from "@yusufstar07/sdk-client";

License

UNLICENSED - Private package