Skip to content

Instantly share code, notes, and snippets.

View blogcacanid's full-sized avatar

Rony Chandra Kudus blogcacanid

  • cacan.id
  • Jakarta
View GitHub Profile
@blogcacanid
blogcacanid / index.js
Created November 11, 2020 23:49
index.js Authentication JWT React JS Lumen 7
import { combineReducers } from "redux";
import auth from "./auth";
import message from "./message";
export default combineReducers({
auth,
message,
});
@blogcacanid
blogcacanid / auth.js
Created November 11, 2020 23:48
auth.js Authentication JWT React JS Lumen 7
import {
REGISTER_SUCCESS,
REGISTER_FAIL,
LOGIN_SUCCESS,
LOGIN_FAIL,
LOGOUT,
} from "../actions/types";
const user = JSON.parse(localStorage.getItem("user"));
@blogcacanid
blogcacanid / message.js
Created November 11, 2020 23:48
message.js Authentication JWT React JS Lumen 7
import { SET_MESSAGE, CLEAR_MESSAGE } from "../actions/types";
const initialState = {};
export default function (state = initialState, action) {
const { type, payload } = action;
switch (type) {
case SET_MESSAGE:
return { message: payload };
@blogcacanid
blogcacanid / auth.js
Created November 11, 2020 23:47
auth.js Authentication JWT React JS Lumen 7
import {
REGISTER_SUCCESS,
REGISTER_FAIL,
LOGIN_SUCCESS,
LOGIN_FAIL,
LOGOUT,
SET_MESSAGE,
} from "./types";
import AuthService from "../services/auth.service";
@blogcacanid
blogcacanid / message.js
Created November 11, 2020 23:46
message.js Authentication JWT React JS Lumen 7
import { SET_MESSAGE, CLEAR_MESSAGE } from "./types";
export const setMessage = (message) => ({
type: SET_MESSAGE,
payload: message,
});
export const clearMessage = () => ({
type: CLEAR_MESSAGE,
});
@blogcacanid
blogcacanid / types.js
Created November 11, 2020 23:46
types.js Authentication JWT React JS Lumen 7
export const REGISTER_SUCCESS = "REGISTER_SUCCESS";
export const REGISTER_FAIL = "REGISTER_FAIL";
export const LOGIN_SUCCESS = "LOGIN_SUCCESS";
export const LOGIN_FAIL = "LOGIN_FAIL";
export const LOGOUT = "LOGOUT";
export const SET_MESSAGE = "SET_MESSAGE";
export const CLEAR_MESSAGE = "CLEAR_MESSAGE";
@blogcacanid
blogcacanid / user.service.js
Created November 11, 2020 23:45
user.service.js Authentication JWT React JS Lumen 7
import axios from "axios";
// For Lumen 7 back-end
const API_URL = "http://localhost:8000/api/test/";
// for Node.js Express back-end
// const API_URL = "http://localhost:9090/api/test/";
const getPublicContent = () => {
return axios.get(API_URL + "all");
};
@blogcacanid
blogcacanid / auth-header.js
Created November 11, 2020 23:44
auth-header.js Authentication JWT React JS Lumen 7
export default function authHeader() {
const user = JSON.parse(localStorage.getItem("user"));
if (user && user.accessToken) {
// For Lumen 7 back-end
return { Authorization: "Bearer " + user.accessToken };
// for Node.js Express back-end
// return { "x-access-token": user.accessToken };
} else {
@blogcacanid
blogcacanid / auth.service.js
Created November 11, 2020 23:43
auth.service.js Authentication JWT React JS Lumen 7
import axios from "axios";
// For Lumen 7 back-end
const API_URL = "http://localhost:8000/api/auth/";
// for Node.js Express back-end
// const API_URL = "http://localhost:9090/api/auth/";
const register = (username, email, password) => {
return axios.post(API_URL + "register", {
username,
@blogcacanid
blogcacanid / app-routing.module.ts
Created November 9, 2020 22:06
app-routing.module.ts Authentication JWT Angular 9 Lumen 7
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { RegisterComponent } from './register/register.component';
import { LoginComponent } from './login/login.component';
import { ProfileComponent } from './profile/profile.component';
import { HomeComponent } from './home/home.component';
const routes: Routes = [
{ path: 'home', component: HomeComponent },