Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
I may be slow to respond back

codeclassifiers

💭
I may be slow to respond back
View GitHub Profile
@codeclassifiers
codeclassifiers / githubJobscors.js
Created Sep 26, 2020
Github jobs access with cors
View githubJobscors.js
const express = require('express')
const cors = require('cors')
const app = express()
const axios = require('axios')
app.use(cors())
app.use(express.json())
app.get('/jobs_list', async function (req, res) {
const skill = req.query.skill;
axios.get(`https://jobs.github.com/positions.json?search=${skill}`)
.then(function (response) {
View alert.css
.alert { color: #000;}
.alert__title { padding: 10px;}
.track__title:hover, .track-title:focus { color: blue}
View alert.scss
.alert {
color: #000;
&__title {
paddding: 10px;
&:hover {
color: blue;
}
}
}
View sample.css
.list {
color: beige;
}
.alert {
color: beige;
}
View sample.sass
$primary-color: beige
.list
color: $primary-color
.alert
color: $primary-color
View sample.scss
/* SCSS */
$primary-color: beige;
.list {
color: $primary-color;
}
.alert {
color: $primary-color;
}
View headerupdated.js
function Header(props) {
...
function renderLogout() {
if(props.location.pathname === '/home'){
return(
<div className="ml-auto">
<button className="btn btn-danger" onClick={() => handleLogout()}>Logout</button>
</div>
)
}
View auth.js
const jwt = require("jsonwebtoken");
const User = require('../models/User');
module.exports = async function(req, res, next) {
const token = req.header("token");
if (!token) return res.status(401).json({ message: "Auth Error" });
try {
const decoded = jwt.verify(token, "randomString");
req.user = decoded.user;
const user = await User.findById(decoded.user.id);
View fetchCall.js
function Home(props) {
useEffect(() => {
axios.get(API_BASE_URL+'/user/me', { headers: { 'token': localStorage.getItem(ACCESS_TOKEN_NAME) }})
.then(function (response) {
if(response.status !== 200){
redirectToLogin()
}
})
.catch(function (error) {
redirectToLogin()
View privateroute2.js
...
import PrivateRoute from './utils/PrivateRoute';
...
<Switch>
.....
<PrivateRoute path="/home">
<Home/>
</PrivateRoute>
</Switch>