j-tockauth
TypeScript icon, indicating that this package has built-in type declarations

1.2.7 • Public • Published

J-tockauth

A connector for javascript application frontend to Ruby on Rails with Devise Token Auth gem backend

Usage

import JtockAuth from "j-tockauth";
 
const auth = new JtockAuth({
  host: "http://127.0.0.1:3000",
  prefixUrl: "/api/v1",
  debug: false
});
 
export default auth;

SignUp

import auth from "./auth";
 
auth
  .signUp(
    {
      email: "john-doe@gmail.com",
      password: "myP@ssw0ord!",
      avatarUrl: "www.image.com/picture.jpg"
    },
    "www.url-after-confirmation.com"
  )
  .then(userDatas => {
    console.log(userDatas);
  })
  .catch(error => {
    console.log(error);
  });

SignIn

import auth from "./auth";
 
auth
  .signIn("john-doe@gmail.com", "myP@ssw0ord!")
  .then(userDatas => {
    console.log(userDatas);
  })
  .catch(error => {
    console.log(error);
  });

SignOut (need an active session)

import auth from "./auth";
 
auth
  .signOut()
  .then(response => {
    console.log(response);
  })
  .catch(error => {
    console.log(error);
  });

Delete resource (need an active session)

import auth from "./auth";
 
auth
  .deleteResource()
  .then(response => {
    console.log(response);
  })
  .catch(error => {
    console.log(error);
  });

Change password (need an active session)

import auth from "./auth";
 
auth
  .changePassword("myP@ssw0ord!", "newp@SSw0rd", "newp@SSw0rd")
  .then(response => {
    console.log(response);
  })
  .catch(error => {
    console.log(error);
  });

Send reset password link and token by email

import auth from "./auth";
 
auth
  .resetPassword("john-doe@gmail.com", "www.reset-password-link.com")
  .then(response => {
    console.log(response);
  })
  .catch(error => {
    console.log(error);
  });

Update password after email reset

import auth from "./auth";
 
auth
  .updatePasswordByToken(
    "jd97-MDsj763fsGSU",
    "www.url-after-reset-password-success.com"
  )
  .then(response => {
    console.log(response);
  })
  .catch(error => {
    console.log(error);
  });

Protected routes

import auth from "./auth";
 
auth
  .authenticateRoute("/posts", {
    method: "POST",
    // data can be an json object or a FormData
    data: { title: "My post title", body: "My post body", user_id: 1 }
  })
  .then(postsResponse => {
    console.log(postsResponse);
  })
  .catch(error => {
    console.log(error);
  });

Readme

Keywords

Package Sidebar

Install

npm i j-tockauth

Weekly Downloads

1

Version

1.2.7

License

ISC

Unpacked Size

271 kB

Total Files

17

Last publish

Collaborators

  • eth3rnit3