Add logger + lint

This commit is contained in:
Barry Low committed 2018-10-11 16:16:29 -07:00
1 parent 401fb88e0e
commit 7e6f987e2a
7 files changed
+197 -25

No files matched your search

+24 -15
View File
@@ -1,8 +1,9 @@
import Auth0Lock from 'auth0-lock'
import gql from 'graphql-tag'
import { getItem, setItem, removeItem } from '../utils/local-storage'
import { getItem, setItem } from '../utils/local-storage'
import { validObject, deleteCookie } from '../utils/js-helpers'
import Log from '../utils/log'
import { client } from '../graphql/apollo'
@@ -10,7 +11,7 @@ import { AUTH_CONFIG } from './Auth0' // create by renaming Auth0.sample.js to A
const AUTHENTICATE = gql`
mutation authenticate($idToken: String!) {
TeamsModuleauthenticate(idToken: $idToken) {
TeamsModuleAuthenticate(idToken: $idToken) {
alias
authId
}
@@ -60,7 +61,11 @@ export const inviteOptions = {
prefill: { email: '' }
}
let lock = new Auth0Lock(AUTH_CONFIG.clientId, AUTH_CONFIG.domain, defaultOptions)
let lock = new Auth0Lock(
AUTH_CONFIG.clientId,
AUTH_CONFIG.domain,
defaultOptions
)
class Auth {
constructor (cb, apolloClient) {
@@ -77,6 +82,7 @@ class Auth {
login () {
// Call the show method to display the widget.
Log.info('logging in')
lock.show()
}
@@ -89,17 +95,23 @@ class Auth {
variables: { token: jwt }
})
console.log('loginInvite auth: ', await data.data.verifyTeamInvite)
Log.info('auth.loginInvite')
Log.info(await data.data.verifyTeamInvite)
setItem('invite', JSON.stringify(data.data.verifyTeamInvite))
email = data.data.verifyTeamInvite.email
team = data.data.verifyTeamInvite.team.slug
} catch (err) {
return console.log('loginInvite err: ', err)
return Log.error(err, 'loginInvite err: ')
}
inviteOptions.prefill.email = email
inviteOptions.auth.params.state = `${email}|${team}`
let lockInvite = new Auth0Lock(AUTH_CONFIG.clientId, AUTH_CONFIG.domain, inviteOptions)
let lockInvite = new Auth0Lock(
AUTH_CONFIG.clientId,
AUTH_CONFIG.domain,
inviteOptions
)
lockInvite.show()
}
@@ -151,7 +163,8 @@ class Auth {
idToken: authResult.idToken,
expiresAt
}
console.log('setSession idTokenPayload: ', authResult.idTokenPayload)
Log.info('setSession idTokenPayload:')
Log.info(authResult.idTokenPayload)
this.signinOrCreateAccount({ ...data })
this.cb(data)
@@ -173,10 +186,11 @@ class Auth {
mutation: AUTHENTICATE,
variables: { idToken }
})
Log.info('auth.signinOrCreateAccount data:')
Log.info(await data)
const user = {
authId: data.data.authenticate.authId,
alias: data.data.authenticate.alias
authId: await data.TeamsModuleAuthenticate.authId,
alias: await data.TeamsModuleAuthenticate.alias
}
setItem('user', JSON.stringify(user))
if (window.location.href.includes(`callback`)) {
@@ -190,11 +204,6 @@ class Auth {
logout () {
// Clear access token and ID token from local storage
removeItem('access_token')
removeItem('id_token')
removeItem('expires_at')
removeItem('authUser')
removeItem('auth0.ssodata')
window.localStorage.clear()
deleteCookie('ajs_anonymous_id')
deleteCookie('ajs_user_id')
+4
View File
@@ -4,6 +4,10 @@ import ReactDOM from 'react-dom'
import MasterApp from './App'
if (process.env.NODE_ENV !== 'production') {
localStorage.setItem('debug', 'advanced-algos:*')
}
ReactDOM.render(<MasterApp />, document.getElementById('root'))
let frontendReloadCount = 0
+1 -5
View File
@@ -2,8 +2,4 @@ const getItem = async name => window.localStorage.getItem(name)
const setItem = async (name, value) => window.localStorage.setItem(name, value)
const removeItem = async name => window.localStorage.removeItem(name)
export {
getItem,
setItem,
removeItem
}
export { getItem, setItem, removeItem }
+39
View File
@@ -0,0 +1,39 @@
import debug from 'debug'
const BASE = 'advanced-algos'
const COLOURS = {
info: 'blue',
warn: 'orange',
error: 'red'
}
class Log {
generateMessage (level, message, source) {
// Set the prefix which will cause debug to enable the message
const namespace = `${BASE}:${level}`
const createDebug = debug(namespace)
// Set the colour of the message based on the level
createDebug.color = COLOURS[level]
if (source) {
createDebug(source, message)
} else {
createDebug(message)
}
}
info (message, source) {
return this.generateMessage('info', message, source)
}
warn (message, source) {
return this.generateMessage('warn', message, source)
}
error (message, source) {
return this.generateMessage('error', message, source)
}
}
export default new Log()
+1 -2
View File
@@ -68,9 +68,8 @@ const Footer = ({ classes }) => {
</NavLink>
</Grid>
<Grid item xs>
<Typography variant='h6' color='textPrimary' gutterBottom>
Support
Support
</Typography>
<a