j-tockauth
v1.2.7
Published
javascript connector for DeviseTokenAuth for Ruby on Rails
Downloads
57
Readme
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: "[email protected]",
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("[email protected]", "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("[email protected]", "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);
});