MYTPEN Auth Integration Package

1.1.15 · active · verified Wed Apr 22

The `mytpen-auth` package, currently at version 1.1.15, is designed to provide a robust and simplified authentication integration solution for applications leveraging MYTPEN's OIDC (OpenID Connect) services, with a strong focus on Next.js `app` directory projects. It abstracts the complexities of OIDC flows by offering pre-built API route handlers and React context providers, streamlining the setup process significantly. A key feature is its requirement for Redis (via `@upstash/redis`) for secondary storage, enabling efficient session management and state persistence across serverless functions. The package ships with comprehensive TypeScript types, ensuring a type-safe development experience. It operates on Node.js environments version 18.0.0 or higher and has peer dependencies on React and React DOM, both version 19.0.0 or higher. The package undergoes iterative development, with minor version updates reflecting ongoing enhancements and specific platform integrations.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates the essential configuration for `mytpen-auth` within a Next.js `app` directory project. It includes setting up the API route handler, integrating `MytpenAuthProvider` into the root layout, and highlights the critical environment variables required for successful authentication and Redis integration.

    // In your .env file (or configured in deployment environment):
    // MYTPEN_AUTH_SECRET="your-strong-random-secret-key"
    // MYTPEN_PROVIDER_ID="your-app-id-from-dashboard"
    // MYTPEN_CLIENT_ID="your-client-id-from-dashboard"
    // MYTPEN_CLIENT_SECRET="your-client-secret-from-dashboard"
    // MYTPEN_AUTH_SERVER="https://dashboard.mytpen.app" (or your IdP origin)
    // MYTPEN_AUTH_BASEURL="http://localhost:3000" (or your app's base URL for callbacks)
    // UPSTASH_REDIS_REST_URL="https://your-instance.upstash.io"
    // UPSTASH_REDIS_REST_TOKEN="your-upstash-rest-token"

    // app/api/auth/[...all]/route.ts
    import { auth, toNextJsHandler } from "mytpen-auth";

    // Export GET and POST handlers for the Next.js API route
    export const { GET, POST } = toNextJsHandler(auth);

    // app/layout.tsx
    import { MytpenAuthProvider } from "mytpen-auth/provider";
    import { LogoSvg } from "mytpen-auth/components"; // Example component (optional)
    import { getCurrentPathname } from "mytpen-auth/nextjs"; // Example utility (optional)
    import "./globals.css"; // Assuming you have global styles

    export default function RootLayout({
      children,
    }: {
      children: React.ReactNode;
    }) {
      const pathname = getCurrentPathname(); // Example usage of a utility

      return (
        <html lang="en">
          <body>
            <MytpenAuthProvider>
              <header style={{ display: 'flex', justifyContent: 'space-between', padding: '1rem', borderBottom: '1px solid #eee' }}>
                <LogoSvg width={100} height={30} />
                <nav>
                  <a href="/dashboard" style={{ margin: '0 0.5rem' }}>Dashboard</a>
                  <a href="/profile" style={{ margin: '0 0.5rem' }}>Profile</a>
                  <a href="/api/auth/signout" style={{ margin: '0 0.5rem' }}>Sign Out</a>
                </nav>
              </header>
              <main style={{ minHeight: '80vh', padding: '2rem' }}>
                {children}
              </main>
              <footer style={{ marginTop: '2rem', textAlign: 'center', color: '#888' }}>
                <p>Application Footer - Current Path: {pathname}</p>
              </footer>
            </MytpenAuthProvider>
          </body>
        </html>
      );
    }
    

view raw JSON →