Coder Social home page Coder Social logo

api-e-commerce's Introduction

Electronic Store

Electronic Store Logo

Electronic Store is an e-commerce project built to provide a convenient and reliable shopping experience for customers. This project uses Node.js and Express.js for the backend, React for the frontend, and MongoDB as the database.

Table of Contents

Installation

Before running the installation command, make sure you have MongoDB installed and running on your machine. Also, ensure you have Node.js installed.

1. Clone the repository:

git clone https://github.com/ThanhSon1506/api-e-commerce.git

2. Install package npm:

 npm install 

3. Run database

 npm run data:backup

4. Run start project

 npm run dev

5. Run build project

   npm run build

api-e-commerce's People

Contributors

thanhson1506 avatar trongharavan avatar luongxuan11 avatar

Watchers

 avatar

api-e-commerce's Issues

[Project] dự án cá nhân

học thêm: Web API xử lý bất đồng bộ


Project cá nhân(basic)

  • login, resgister, logout(xóa token trong local storage và db)
  • jwt token access, refresh(db) lưu vào local storage

phải có xác thực -> trước khi sendfile product.html thì check authenticate
-> nếu pass thì send về cho client -> ngược lại redirect sang login

  • sản phẩm(tên giá)
    • listing
    • tạo sản phẩm
    • chi tiết
    • sửa

[WEB] handle 401 unauthorized

import axios from "axios";
import createAuthRefreshInterceptor from "axios-auth-refresh";
import { isLogin } from "../helper/auth/auth";
import Logger from "../helper/utils/logger";

const http = axios.create({
baseURL: process.env.REACT_APP_API_URL,
});

// Obtain the fresh token each time the function is called
function getAccessToken() {
return localStorage.getItem("token");
}

// Obtain the user token each time the function is called
function getUserToken() {
const user = JSON.parse(localStorage.getItem("user"));
if (user && user.token) {
return "Bearer " + user.token;
} else {
return "";
}
}

// Use interceptor to inject the token to requests
http.interceptors.request.use((request) => {
request.headers["Authorization"] = ${getAccessToken()};
if (isLogin()) request.headers["UserToken"] = ${getUserToken()};
return request;
});

// Function that will be called to refresh authorization
const refreshAuthLogic = (failedRequest) =>
http
.post("/auth", {
appId: process.env.REACT_APP_API_URL,
secretKey: process.env.REACT_APP_API_URL,
})
.then((response) => {
Logger.info("Renew token: " + response.headers.authorization);
localStorage.setItem("token", response.headers.authorization);
failedRequest.response.config.headers["Authorization"] =
response.headers.authorization;
return Promise.resolve();
});

// Instantiate the interceptor (you can chain it as it returns the axios instance)
createAuthRefreshInterceptor(http, refreshAuthLogic);

export default http;

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.