Skip to content

Instantly share code, notes, and snippets.

@dhpradeep
Created October 16, 2020 06:02
Show Gist options
  • Save dhpradeep/3386b54106b1a542c389686899efa869 to your computer and use it in GitHub Desktop.
Save dhpradeep/3386b54106b1a542c389686899efa869 to your computer and use it in GitHub Desktop.
Sample
const authLogin = async (email, password) =>
axios.post("/api/token/obtain/", { email, password })
import { login, logoutSuccess } from "../../src/redux/auth/action"
import Config from "./config"
Cypress.Commands.add("loginAs", (role) => {
const user = Config.users[role]
cy.log(`Logging with ${user.email} as role of ${role}`)
login(user.email, user.password)
})
Cypress.Commands.add("logout", () => {
cy.log("Logging out user!!")
logoutSuccess()
window.localStorage.clear()
window.sessionStorage.clear()
})
const Config = {
users: {
admin: {
email: "admin@admin.com",
password: "admin12345"
},
staff: {
email: "staff@staff.com",
password: "staff12345"
}
}
}
export default Config
import {authLogin} from "axios"
const login = (username, password) => (dispatch) => {
dispatch(loadBegin())
return authLogin(username, password)
.then((res) => {
// successfully logged in
dispatch(loginSuccess(res.data, username))
dispatch(loadEnd())
return true
})
.catch((err) => {
error(err)
dispatch(loadEnd())
return false
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment