Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions client/src/components/ItemDisplayComp.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ class ItemDisplayComp extends React.Component {
var self = this;
axios
.get("api/items")
.then(function(response) {
.then(function (response) {
self.setState({ items: response.data });
})
.catch(function(error) {
.catch(function (error) {
console.log(error);
});
}
Expand All @@ -38,7 +38,7 @@ class ItemDisplayComp extends React.Component {
href={"/#/viewItem/" + item._id + "/#"}
className="card-img-top-new"
>
<img src={item.imageLocation} className="card-img-top-new"/>
<img src={item.imageLocation} className="card-img-top-new" />
</a>
<div className="card-body">
<h5>{item.name}</h5>
Expand All @@ -52,7 +52,7 @@ class ItemDisplayComp extends React.Component {
</p>
<div className="d-flex justify-content-between align-items-center">
<div className="btn-group">
<a href={"/#/viewItem/"+item._id}
<a href={"/#/viewItem/" + item._id}
type="button"
className="btn btn-sm btn-outline-secondary"
>
Expand Down
8 changes: 4 additions & 4 deletions client/src/components/LoginFormComp.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import React, { Component } from "react";
import axios from "axios";
import Facebook from "./Facebook";
import authService from "./services/AuthServices";

class LoginFormComp extends Component {
constructor(props) {
super(props);
this.state = {};
this.onValuChange = this.onValuChange.bind(this);
this.onSubmit = this.onSubmit.bind(this);
}

onValuChange(e) {
onValuChange=(e)=> {
this.setState({ [e.target.name]: e.target.value });
}

onSubmit(e) {
onSubmit=(e)=> {
e.preventDefault();
axios
.post("/api/auth/login", this.state)
.then(res => {
console.log(res);
authService.setAuthDetail(res.data)
sessionStorage.setItem(
"user",
JSON.stringify({ jwtToken: res.data.token, userId: res.data.userId, name:res.data.name })
Expand Down
20 changes: 20 additions & 0 deletions client/src/components/services/AuthServices.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

class AuthService {

setAuthDetail(data) {
sessionStorage.setItem('token', data.token);
sessionStorage.setItem('id', data.user.id);
sessionStorage.setItem('name',data.user.username)
}
getAuthToken() {
const token = sessionStorage.getItem('token');
return token;
}
getLoggedUser(){
const id = sessionStorage.getItem('id');
const name = sessionStorage.getItem('name');
return {Id:id,Name:name};
}
}
const authService = new AuthService();
export default authService;
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.