Skip to content

Instantly share code, notes, and snippets.

View elsetiyawan's full-sized avatar

Lilik Setiyawan elsetiyawan

  • Yogyakarta, Indonesia
View GitHub Profile
export async function refreshToken() {
const token = getCookie("ACCESS_TOKEN");
const refresh_token = getCookie("REFRESH_TOKEN");
const SERVER_DOMAIN = process.env.REACT_APP_API_ENDPOINT;
const current_time = new Date();
if (token !== "") {
const decodeToken = jwt(token);
if (current_time.getTime() > decodeToken.exp * 1000) {
return Axios.post(`${SERVER_DOMAIN}v1/auth/refresh`, {
refreshToken: refresh_token,
import * as axios from "axios";
import { getCookie, refreshToken } from "./utils";
export default class Api {
constructor() {
this.api_token = null;
this.client = null;
this.api_url = process.env.REACT_APP_API_ENDPOINT;
}
@elsetiyawan
elsetiyawan / App.js
Last active July 10, 2020 10:18
App.js example in API Call Best Practice
import React from "react";
import "./App.css";
import Api from "./helper/api";
function App() {
const api = new Api();
const fetchUser = () => {
api
.getUserList()
import * as axios from "axios";
import { getCookie } from "./utils";
export default class Api {
constructor() {
this.api_token = null;
this.client = null;
this.api_url = process.env.REACT_APP_API_ENDPOINT;
}