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

@genezio/auth

v2.1.2

Published

SDK for accessing genezio authentication system.

Downloads

1,231

Readme

npm-version

What is @genezio/auth

@genezio/auth is a package that provided by genezio to ensure comprehensive solutions for integrating various authentication providers into a genezio application.

Table of Contents

Features

  • 📦  Provides comprehensive solutions for integrating various authentication providers into a genezio application.
  • 📱  Google, Email & Password login.
  • 🧰  Session management.
  • 📝  Token storage customization.
  • 📬  Email verification.
  • 📧  Password reset.
  • 📡  Detailed error codes.

Getting Started

Install @genezio/auth

To install the @genezio/auth package, you can use npm or yarn:

npm install @genezio/auth
yarn add @genezio/auth

Examples

Configuration

At the beginning you need to configure the authentication token and region of your genezio application. These can be found Authentication Configuration screen on the genezio Dashboard.

import { AuthService } from "@genezio/auth";

AuthService.getInstance().setTokenAndRegion("<token>", "<region>");

Register with Email & Password

This will trigger the AuthService's register method whenever someone clicks the "Sign Up" button:

const handleSubmit = async (event: React.FormEvent) => {
  event.preventDefault();
  setLoading(true);
  try {
      const response = await AuthService.getInstance().register(email, password, name);
      console.log('Register Success', response);

      navigate('/login');
  } catch (error: any) {
      console.log(error);
      alert("An error has occured")
  }
  setLoading(false);
};

Login with Email & Password

This will trigger the AuthService's login method whenever someone clicks the "Login" button:

const handleSubmit = async (event: React.FormEvent) => {
    event.preventDefault();
    setLoginLoading(true);

    try {
        await AuthService.getInstance().login(email, password)
        navigate("/");
    } catch (error: any) {
        console.log('Login Failed', error);
        alert('Login Failed');
    }
    setLoginLoading(false);
}

Google Login

This will trigger the AuthService's googleRegistration method whenever someone clicks the Google login button:

const handleGoogleLogin = async (credentialResponse: CredentialResponse) => {
    console.log(credentialResponse);
    setGoogleLoginLoading(true);

    try {
        await AuthService.getInstance().googleRegistration(credentialResponse.credential!)

        console.log('Login Success');
        navigate('/');
    } catch(error: any) {
        console.log('Login Failed', error);
        alert('Login Failed');
    }
    setGoogleLoginLoading(false);
};

Verify if user is logged in

The userInfo method on the AuthService is for getting the user's information. You can use this method to check if the user is logged in or not.

useEffect(() => {
    if (name && email) {
        return;
    }

    AuthService.getInstance().userInfo().then((user) => {
        setName(user.name!);
        setEmail(user.email);
    }).catch((error) => {
        console.error(error);
    })
}, []);

Logout

The logout method on the AuthService is for logging the user out.

const logout = async () => {
  try {
      await AuthService.getInstance().logout();
      navigate('/login');
  } catch (error) {
      console.error(error);
  }
}

Handling Errors

The ErrorCode enum contains all the error codes that can be thrown by the @genezio/auth package.

import { AuthService, ErrorCode } from '@genezio/auth';
const handleSubmit = async (event: React.FormEvent) => {
    event.preventDefault();
    setLoading(true);
    try {
        const response = await AuthService.getInstance().register(email, password, name);
        console.log('Register Success', response);

        navigate('/login');
    } catch (error: any) {
        console.log(error);
        if (error.code === ErrorCode.EMAIL_ALREADY_EXISTS) {
            alert("Email already exists")
        } else { 
            alert("An error has occured")
        }
    }
    setLoading(false);
};

Backend Integration

Here getSecret method is protected by @GnzAuth decorator. This will ensure that only authenticated users can access this method.

import { GenezioDeploy, GenezioMethod, GnzAuth, GnzContext } from "@genezio/types";

@GenezioDeploy()
export class BackendClass {
  secret: string = "Hello World!";

  @GenezioMethod()
  @GnzAuth()
  async getSecret(context: GnzContext) {
    console.log(context.user);
    return this.secret;
  }
}

Documentation

To find more details on how to use @genezio/auth, check out the official documentation

Here you can find some examples:

To find more details on how to use genezio, check out the official documentation:

If you cannot find what you are looking for in the docs, don't hesitate to drop us a GitHub issue or start a discussion on Discord.

Getting support

We are here to assist you with any problems or questions you may have while using @genezio/auth. Don't hesitate to reach out to us on GitHub or join our Discord community for real-time assistance.

System requirements

@genezio/auth can be used in Genezio projects developed on macOS, Linux-based distributions, and Windows.

It is designed to work with Node.js versions >= 16.0.0.

Troubleshooting

For the most common issues that our users have dealt with, we created a Troubleshooting section in the documentation.

If you don't find the guidance there, drop us a GitHub issue. We are more than happy to help you!

Contributing

Contributions are welcome! Please see our Contributing Guide for more details.

Show your support by giving us a star :star:, to help others discover genezio and become part of our community!

Ecosystem

There are a growing number of awesome projects deployed with genezio and we want to shout out about them.

If you deployed a project using genezio let us know on Discord and we will add it to our Hall Of Fame.

Badge

Brag to your friends that you are using genezio with this awesome badge -> deployed with: genezio

[![deployed with: genezio](https://img.shields.io/badge/deployed_with-genezio-6742c1.svg?labelColor=62C353&style=flat)](https://github.com/genez-io/genezio)

License

@genezio/auth is licensed under GNU General Public License v3.0. For more information, please refer to LICENSE