1.2.7 • Published 5 years ago

j-tockauth v1.2.7

Weekly downloads
24
License
ISC
Repository
github
Last release
5 years ago

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);
  });
1.2.7

5 years ago

1.2.6

5 years ago

1.2.5

5 years ago

1.2.4

5 years ago

1.2.3

5 years ago

1.2.2

5 years ago

1.2.1

5 years ago

1.1.1

5 years ago

1.0.15

6 years ago

1.0.14

6 years ago

1.0.13

6 years ago

1.0.12

6 years ago

1.0.11

6 years ago

1.0.10

6 years ago

1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago