Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Makoto Ishida mikehibm

🏠
Working from home
View GitHub Profile
View google-api.js
const GOOGLE_CLIENT_ID = process.env.REACT_APP_CLIENTID;
const GOOGLE_API_KEY = process.env.REACT_APP_APIKEY;
const DISCOVERY_DOCS = [
'https://www.googleapis.com/discovery/v1/apis/drive/v3/rest',
];
const SCOPES = 'https://www.googleapis.com/auth/drive.file';
const UPLOAD_URL = 'https://www.googleapis.com/upload/drive/v3/files';
const UPLOAD_PARAMS = '?uploadType=multipart&fields=id';
View auth-state.js
import React, { createContext, useReducer, useEffect } from 'react';
import { init, signIn, signOut } from './google-auth';
const AuthStateContext = createContext();
function authReducer(state, action) {
console.log('authReducer', state, action);
switch (action.type) {
case 'SIGN_IN': {
View google-auth.js
/* eslint-disable no-undef */
const config = {
clientId: process.env.REACT_APP_CLIENTID,
scope: 'profile email',
};
export function init(onInit) {
if (!gapi) {
throw new Error('Google API SDK is not loaded.');
View todo-service.js
import { API, Auth } from 'aws-amplify';
const apiName = 'amplifytest01api';
const apiPath = '/todos';
const userIdPrefix = 'user:';
const defaultOptions = {
headers: {},
response: true,
};
View app.js
const AWS = require('aws-sdk');
var awsServerlessExpressMiddleware = require('aws-serverless-express/middleware');
var bodyParser = require('body-parser');
var express = require('express');
//(中略)
const userIdPresent = true;
const partitionKeyName = 'pk';
const partitionKeyType = 'S';
View index.js
import Amplify from 'aws-amplify';
import { AmplifyAuthenticator, AmplifySignUp } from '@aws-amplify/ui-react';
import awsconfig from '../aws-exports';
import { MyLayout } from '../components/MyLayout';
import { TodoApp } from '../components/TodoApp';
Amplify.configure(awsconfig);
const contentStyle = {
paddingLeft: '0',
View login.js
import React from 'react';
import Amplify from 'aws-amplify';
import { AmplifyAuthenticator, AmplifySignOut } from '@aws-amplify/ui-react';
import awsconfig from '../aws-exports';
import { MyLayout } from '../components/MyLayout';
Amplify.configure(awsconfig);
const contentStyle = {
paddingLeft: '0',
@mikehibm
mikehibm / tsconfig.worker.js
Created Mar 8, 2019
TypeScript config for WebWorker
View tsconfig.worker.js
{
"compilerOptions": {
"target": "es5",
"lib": ["dom", "esnext", "webworker"],
"allowJs": false,
"skipLibCheck": true,
"esModuleInterop": true,
"listEmittedFiles": true,
"allowSyntheticDefaultImports": true,
"strict": true,
View static.config.js
export default {
getSiteData: () => ({
siteTitle: 'Example Site',
gaID: 'UA-222333XXX-1'
}),
getRoutes: async () => {
//(... omitted ...)
}
};
View App.js
const App = () => (
<React.Fragment>
<GoogleAnalytics />
<Router>
  (...)
</Router>
</React.Fragment>
);