This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const credentials = require( './credentials.json' ) | |
const GOOGLE_CLIENT_ID = credentials.google.client_id; | |
const { OAuth2Client } = require( 'google-auth-library' ); | |
var client = new OAuth2Client( GOOGLE_CLIENT_ID, '', '' ); | |
//return a promise with user informations | |
module.exports.getGoogleUser = ( code ) => { | |
//verify the token using google client | |
return client.verifyIdToken( { idToken: code, audience: GOOGLE_CLIENT_ID } ) | |
.then( login => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var express = require( 'express' ); | |
var bodyParser = require( 'body-parser' ); | |
var googleAuth = require( './googleAuth.js' ); | |
var app = express(); | |
var jwt = require('./jwt.js') | |
app.use( bodyParser.json() ); | |
app.use( bodyParser.urlencoded( { extended: false } ) ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var jwt = require( 'jsonwebtoken' ); | |
const secret = require( './credentials.json' ).jwt.secret | |
var createToken = ( user ) => { | |
return "thisisthetokenof:" + user.id | |
} | |
module.exports.verify = ( token ) => { | |
try { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const credentials = require( './credentials.json' ).facebook | |
const { client_id, client_secret } = credentials; | |
var fetch = require( 'node-fetch' ); | |
module.exports.getUser = ( code ) => { | |
let appToken; | |
let url = 'https://graph.facebook.com/oauth/access_token?client_id=' + client_id + '&client_secret=' + client_secret + '&grant_type=client_credentials'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var jwt = require('./jwt'); | |
const checkToken = ( req ) => { | |
//get the http header 'authorization' | |
let authorization = req.get( 'authorization' ); | |
if ( !authorization ) { | |
throw new Error( 401 ) | |
} | |
//check the token signature with 'jwt.js' library | |
let token = authorization.replace( 'Bearer ', '' ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import LoadingOverlay from './Loader' | |
export default (loader, props) => ( | |
class AsyncComponent extends React.Component { | |
constructor(props) { | |
super(props); | |
this.Component = null; | |
this.state = { Component: AsyncComponent.Component }; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const asyncForEach = async (array, callback) => { | |
for (let index = 0; index < array.length; index++) { | |
await callback(array[index], index, array); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const img = "/images/jason-leung-HM6TMmevbZQ-unsplash.jpg"; | |
const text = "Take a look at this brand new t-shirt!"; | |
const title = "New Product Available"; | |
const options = { | |
body: text, | |
icon: "/images/jason-leung-HM6TMmevbZQ-unsplash.jpg", | |
vibrate: [200, 100, 200], | |
tag: "new-product", | |
image: img, | |
badge: "https://spyna.it/icons/android-icon-192x192.png", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* checks if Push notification and service workers are supported by your browser | |
*/ | |
function isPushNotificationSupported() { | |
return "serviceWorker" in navigator && "PushManager" in window; | |
} | |
/** | |
* asks user consent to receive push notifications and returns the response of the user, one of granted, default, denied | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const pushServerPublicKey = "<A PUSH SERVER PUBLIC KEY GOES HERE>"; | |
/** | |
* | |
* using the registered service worker creates a push notification subscription and returns it | |
* | |
*/ | |
function createNotificationSubscription() { | |
//wait for service worker installation to be ready, and then | |
return navigator.serviceWorker.ready.then(function(serviceWorker) { |
OlderNewer