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 🙏

© 2024 – Pkg Stats / Ryan Hefner

goobs-auth

v0.3.0

Published

A comprehensive and customizable authentication solution for applications. Includes flexible auth flows, email/SMS verification, custom middleware, and integration with Twilio and SMTP services.

Downloads

86

Readme

goobs-auth

The NPM repo is available here - https://www.npmjs.com/package/goobs-auth

goobs-auth is a comprehensive authentication solution for Next.js applications. It provides a flexible and customizable authentication flow that can be easily integrated into your projects.

Table of Contents

Installation

To install goobs-auth in your Next.js project, run one of the following commands:

npm install goobs-auth
# or
yarn add goobs-auth

Features

  • Flexible authentication flow with customizable steps
  • Support for email/password, email verification, and SMS verification
  • Integration with Twilio for SMS services
  • SMTP configuration for email services
  • Custom middleware for protecting routes
  • Server-side utilities for token management and verification
  • React components for different authentication steps

Usage

  1. Update your next.config.js:
/** @type {import('next').NextConfig} */
const nextConfig = {
  reactStrictMode: true,
  swcMinify: true,
  transpilePackages: ['goobs-frontend', 'goobs-cache', 'goobs-auth', 'goobs-encryption'],
};

export default nextConfig;
  1. Create an authentication configuration file (e.g., .auth.json) in your project root:
{
  "userModel": {
    "getUser": {
      "path": "./path/to/getUserFunction",
      "exportName": "getUser"
    },
    "setUser": {
      "path": "./path/to/setUserFunction",
      "exportName": "setUser"
    },
    "deleteUser": {
      "path": "./path/to/deleteUserFunction",
      "exportName": "deleteUser"
    }
  },
  "database": {
    "connectScript": "// Your database connection script"
  },
  "authentication": {
    "login": [
      { "step": 1, "type": "enterEmail" },
      { "step": 2, "type": "emailAndPasswordVerification" }
    ],
    "registration": [
      { "step": 1, "type": "enterEmail" },
      { "step": 2, "type": "emailAndPasswordAndVerifyPasswordVerification" },
      { "step": 3, "type": "emailVerification" },
      { "step": 4, "type": "textMessageVerification" },
      { "step": 5, "type": "accountInfo" }
    ],
    "forgotPassword": [
      { "step": 1, "type": "enterEmail" },
      { "step": 2, "type": "emailVerification" }
    ]
  },
  "twilio": {
    "accountSid": "your_twilio_account_sid",
    "authToken": "your_twilio_auth_token",
    "phoneNumber": "your_twilio_phone_number"
  },
  "smtp": {
    "host": "your_smtp_host",
    "port": 587,
    "secure": false,
    "auth": {
      "user": "your_smtp_username",
      "pass": "your_smtp_password"
    },
    "from": "[email protected]"
  }
}
  1. Implement the authentication page in your Next.js app:
// pages/auth.tsx
'use client';

import React from 'react';
import { AppRouterCacheProvider } from '@mui/material-nextjs/v14-appRouter';
import { AuthPageContent } from 'goobs-auth';

export default function AuthPage() {
  return (
    <AppRouterCacheProvider>
      <AuthPageContent />
    </AppRouterCacheProvider>
  );
}
  1. Protect your routes using the authMiddleware:
// middleware.ts
import { authMiddleware } from 'goobs-auth';

export default authMiddleware;

Configuration

The .auth.json file allows you to customize various aspects of the authentication flow:

  • userModel: Define functions for user management (get, set, delete)
  • database: Specify the database connection script
  • authentication: Configure the steps for login, registration, and password recovery
  • twilio: Set up Twilio credentials for SMS services
  • smtp: Configure SMTP settings for email services

API Reference

loadAuthConfig(configPath?: string): Promise<AuthConfig>

Loads the authentication configuration from the specified path or the default locations.

authUtility(options: AuthUtilityOptions): Promise<ValidateResult | LoginResult | LogoutResult>

A comprehensive authentication utility for server components and server actions.

authSpoof(options?: AuthSpoofOptions): Promise<{ isValid: boolean, validTokens: ValidTokens }>

Generates mock authentication data for testing purposes.

Components

goobs-auth provides several React components for building the authentication UI:

  • AuthPageContent: The main authentication page component
  • EnterEmailStep: Component for entering email
  • EmailPasswordVerificationStep: Component for email and password verification
  • EmailVerificationStep: Component for email verification
  • TextMessageVerificationStep: Component for SMS verification
  • AccountInfoStep: Component for collecting additional account information

Server Actions

goobs-auth includes several server-side actions for handling authentication:

  • verifyEmail: Verifies an email address
  • sendEmail: Sends an email (e.g., for verification)
  • sendSMS: Sends an SMS message
  • verifyUser: Verifies a user's phone number

Middleware

The authMiddleware function can be used to protect routes and validate authentication tokens.

License

This project is licensed under the MIT License.

Contact

For questions, feature requests, or support, please contact:

  • Matthew Goluba

For the quickest response, please use email. Our website is currently under development and will be shared here soon.