Skip to content

Instantly share code, notes, and snippets.

const loginWithFacebook = async (req, res, next) => {
try {
const user_resp = await axios.get(`https://graph.facebook.com/${GRAPH_API_VERSION}/me`, {
params: {
fields: "id, name, email, picture",
access_token: req.body.access_token
}
});
req.email = user_resp.data.email
const loginWithGithub = async (req, res, next) => {
try {
// exchange "code" for a access token which never expire as of 201912
const atoken_resp = await axios.post('https://github.com/login/oauth/access_token',
{
client_id: process.env.GITHUB_CLIENT_ID,
client_secret: process.env.GITHUB_CLIENT_SECRET,
code: req.body.code
}
);
const authCheck = (req, res, next) => {
let token = req.headers['x-access-token'] || req.headers['authorization']; // Express headers are auto converted to lowercase
if (token.startsWith('Bearer ')) {
// Remove Bearer from string
token = token.slice(7, token.length);
}
if (!token) return res.status(401).send({ auth: false, message: 'No token provided.' });
jwt.verify(token, process.env.JWT_SECRET, function(err, decoded) {
if (err) {
console.log("==> jwt error: ", err);
function Callback(props) {
const { dispatch } = React.useContext(AuthContext);
const location = useLocation();
useEffect(() => {
async function exchangeToken() {
try {
const resp = await axios.post(process.env.REACT_APP_BACKEND_URL + '/login/github', JSON.stringify({
code: values.code
}), {
@alant
alant / Login.jsx
Last active December 3, 2019 17:26
function Login(props) {
const { state, dispatch } = React.useContext(AuthContext);
const GITHUB_CLIENT_ID = "6e0b5f325ac2e324312c";
const GITHUB_REDIRECT_URI = process.env.REACT_APP_FRONTEND_URL + "/callback";
const handleGithubLogin = event => {
event.preventDefault();
window.open(`https://github.com/login/oauth/authorize?client_id=${GITHUB_CLIENT_ID}&scope=user&redirect_uri=${GITHUB_REDIRECT_URI}`, "_self");
}
...
function* pollSagaWorker(dataKey) {
while (true) {
const contracts = yield select(getContracts);
if (contracts.SimpleStorage.synced) {
const storedValueObj = contracts.SimpleStorage.storedData_[dataKey];
if (storedValueObj && storedValueObj.value) {
yield put({ type: 'GOT_STORED_VALUE', storedValue: storedValueObj.value });
}
}
var SimpleStorage = artifacts.require("./SimpleStorage.sol");
contract('SimpleStorage', function(accounts) {
it("...should start with the value 0.", async function() {
let simpleStorage = await SimpleStorage.deployed();
let storedData = await simpleStorage.storedData_();
assert.equal(storedData.valueOf(), 0, "0 wasn't stored in contract");
});
it("...should store the value 89.", async function() {
let simpleStorage = await SimpleStorage.deployed();
@alant
alant / reducers.js
Last active December 24, 2018 11:16
...
// reducer with initial state
const initialState = {
checkMetaMask: false,
metaMaskReject: false,
checkingTx: false,
txSuccessful: false,
redirectToHome: false,
drizzle: null,
gotStoredValue: false,
@alant
alant / sagas.js
Last active December 24, 2018 11:14
...
function* showMetaMaskOverlay() {
yield put({ type: 'CHECK_METAMASK' });
}
function* showTxErrorMsg() {
yield put({ type: 'TX_ERROR_METAMASK' });
}
function* showCheckingTxMsg() {
@alant
alant / Edit.js
Last active December 24, 2018 11:11
...
class Edit extends Component {
...
handleSubmit = (event) => {
this.contracts.SimpleStorage.methods.set.cacheSend(this.state.newVal);
event.preventDefault();
}
componentDidUpdate(prevProps) {
const { onRedirectToHomeDone } = this.props;