1.1.6 • Published 3 years ago

my-auth-library v1.1.6

Weekly downloads
-
License
MIT
Repository
-
Last release
3 years ago

Installation

With NPM: npm install my-auth-library

With Yarn: yarn add my-auth-library

Usage

Instantiate Auth Object

In your server side code, import and instantiate the Auth object:

import  Auth, { config, baseApiURL } from  "my-auth-library";

// In NextJS
import  getConfig  from  "next/config";
const { serverRuntimeConfig } = getConfig();
const secret = serverRuntimeConfig.secret;

// In ReactJS
// const secret = process.env.SECRET

export { auth };

// Set your API endpoint
config("http://localhost:3000/api");

const  auth = new  Auth("http://localhost:3000/api", secret, "/api/users/authenticate");

Auth Parameters

API root endpoint: String

Secret: String

Authentication endpoint: String

Use userService Utility Methods to Authenticate

import { userService } from  "my-auth-library/dist/services";

// In NextJS
import  getConfig  from  "next/config";
const { publicRuntimeConfig } = getConfig();
const  loginApiUrl = `${publicRuntimeConfig.apiUrl}/users/authenticate`;

// In ReactJS
// const loginApiUrl = process.env.LOGIN_API_URL

const redirect_on_sign_in_url = "/";

function  onSubmit({ username, password }: { [x: string]: string }) {
    return  userService
        .login(username, password, loginApiUrl)
        .then(() => {
        // get return url from query parameters or default to '/'

        let  returnUrl = redirect_on_sign_in_url  || "/";

        router.push({ pathname:  returnUrl });
    })
    .catch((error: string) => {
        console.log(error);
    });
}
1.1.6

3 years ago

1.1.5

3 years ago

1.1.4

3 years ago

1.1.3

3 years ago

1.1.2

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago