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

coax-auth-fe

v1.0.1

Published

This custom `npx` command adds a set of utilities for authentication (login/signup) to your React or Next.js project. It provides hooks for common authentication functionalities and integrates a default interceptor for Axios.

Downloads

8

Readme

Auth Utils for React/Next.js Projects

This custom npx command adds a set of utilities for authentication (login/signup) to your React or Next.js project. It provides hooks for common authentication functionalities and integrates a default interceptor for Axios.

Related resources

Features

  • Hooks for Authentication:
    • useLoginForm: Handle login logic.
    • useRegisterForm: Handle signup logic.
    • useSetNewPassword: Handle password reset logic.
    • useUpdateProfile: Handle user profile updates.
    • withUserProfile: Fetch and manage user profile data.
  • Axios Interceptor:
    • Default interceptor for handling authentication-related API requests. Also includes a refresh token logic.

Installation

Add the authentication utilities to your project by running the following command:

npx coax-auth-fe

Usage

After running the command, the following hooks and Axios interceptor will be added to your project:

Hooks

  1. useLoginForm

    import { useLoginForm } from 'path-to-auth-utils';
    
    const Login = () => {
      const { handleSubmit, setValue, watch, formState } = useLoginForm();
    
      const { errors } = formState;
      const values = watch();
    
      return (
        <form onSubmit={handleSubmit}>
          <label>
           <input type="email" name="email" onChange={e => setValue("email", e.target.value)} value={values.email} />
           { errors.email ? <span>{errors.email.message}</span> : null }
          </label>
           <label>
             <input type="password" name="password" onChange={e => setValue("password", e.target.value)} value={values.password} />
             { errors.password ? <span>{errors.password.message}</span> : null }
           </label>
          <button type="submit">Login</button>
        </form>
      );
    };
  2. useRegisterForm

    import { useRegisterForm } from 'path-to-auth-utils';
    
    const Register = () => {
       const { handleSubmit, setValue, watch, formState } = useRegisterForm();
    
      return (
         <form onSubmit={handleSubmit}>
           <input type="email" name="email" onChange={e => setValue("email", e.target.value)} value={watch("email")} />
           <input type="password" name="password" onChange={e => setValue("password", e.target.value)} value={watch("password")} />
           <input type="password" name="confirmPassword" onChange={e => setValue("confirmPassword", e.target.value)} value={watch("confirmPassword")} />
           <button type="submit">Register</button>
         </form>
      );
    };
  3. useSetNewPassword

    import { useSetNewPassword } from 'path-to-auth-utils';
    
    const SetNewPassword = () => {
      const { handleSubmit, setValue, watch, formState } = useSetNewPassword({ token: "PASS_SECRET_TOKEN_HERE" });
    
      return (
         <form onSubmit={handleSubmit}>
           <input type="password" name="password" onChange={e => setValue("password", e.target.value)} value={watch("password")} />
           <input type="password" name="confirmPassword" onChange={e => setValue("confirmPassword", e.target.value)} value={watch("confirmPassword")} />
           <button type="submit">Set New Password</button>
         </form>
      );
    };
  4. useUpdateProfile

    import { useUpdateProfile } from 'path-to-auth-utils';
    
    const UpdateProfile = () => {
       const { handleSubmit, setValue, watch, formState } = useUpdateProfile();
    
      return (
         <form onSubmit={handleSubmit}>
           <input type="text" name="username" onChange={e => setValue("username", e.target.value)} value={watch("username")} />
           <input type="email" name="email" onChange={e => setValue("email", e.target.value)} value={watch("email")} />
           <button type="submit">Update Profile</button>
         </form>
      );
    };
  5. withUserProfile

    import { withUserProfile, useProfile } from 'path-to-auth-utils';
    
    const UserProfile = () => {
     const { isAuthenticated, profile, logout } = useProfile();
    
      if (!isAuthenticated) return null;
    
      return (
        <div>
          <h1>{profile.username}</h1>
          <p>{profile.email}</p>
        </div>
      );
    };
    
    export withUserProfile(UserProfile);

Configuration

Ensure you have the following environment variables set up in your project for the Axios interceptor to function correctly:

  • REACT_APP_API_URL or NEXT_PUBLIC_API_URL: The base URL of your API.

Contributing

Contributions are welcome! Please open an issue or submit a pull request for any changes or improvements.

License

This project is licensed under the MIT License.


Feel free to customize the file paths and other details as needed for your specific setup.