This file contains 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 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 |
This file contains 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 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 | |
} | |
); |
This file contains 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 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); |
This file contains 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
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 | |
}), { |
This file contains 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
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"); | |
} |
This file contains 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
... | |
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 }); | |
} | |
} |
This file contains 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 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(); |
This file contains 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
... | |
// reducer with initial state | |
const initialState = { | |
checkMetaMask: false, | |
metaMaskReject: false, | |
checkingTx: false, | |
txSuccessful: false, | |
redirectToHome: false, | |
drizzle: null, | |
gotStoredValue: false, |
This file contains 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
... | |
function* showMetaMaskOverlay() { | |
yield put({ type: 'CHECK_METAMASK' }); | |
} | |
function* showTxErrorMsg() { | |
yield put({ type: 'TX_ERROR_METAMASK' }); | |
} | |
function* showCheckingTxMsg() { |
This file contains 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
... | |
class Edit extends Component { | |
... | |
handleSubmit = (event) => { | |
this.contracts.SimpleStorage.methods.set.cacheSend(this.state.newVal); | |
event.preventDefault(); | |
} | |
componentDidUpdate(prevProps) { | |
const { onRedirectToHomeDone } = this.props; |
NewerOlder