Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/authenticated.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react'
import { getLocalToken } from './local-token'
import contextTypes from './context-types'
import AuthContextType from './context-types'

export function hashed(o) {
return Object
Expand Down Expand Up @@ -31,6 +31,6 @@ export const authenticated = () => Component => {
}
}
}
Authed.contextTypes = contextTypes
Authed.contextType = AuthContextType
return Authed
}
33 changes: 17 additions & 16 deletions src/components/auth-context.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react'
import contextTypes from '../context-types'
import AuthContextType from '../context-types'
import PropTypes from 'prop-types'
import { getHashValues } from '../lib/utils'

import TokenManager from './token-manager'
Expand Down Expand Up @@ -40,11 +41,6 @@ class Debug extends React.Component {
}

export class AuthContext extends React.Component {
getChildContext() {
const { provider, clientId, loggingInIndicator } = this.props
return { provider, clientId, loggingInIndicator }
}

isDebugEnabled = () => {
return !!(localStorage.getItem('debug') || '').match(/react-u5auth/)
}
Expand All @@ -59,18 +55,23 @@ export class AuthContext extends React.Component {
console.log('react-u5auth, debug', debug)
return (
<div>
<TokenManager
onTokenUpdate={token => {
this.setState({ token })
onTokenUpdate && onTokenUpdate(token)
}}
/>
{ debug && <Debug contextProps={contextProps} contextState={this.state} hashValues={state} />}
{ showChildren && this.props.children }
<AuthContextType.Provider value={contextProps}>
<TokenManager
onTokenUpdate={token => {
this.setState({ token })
onTokenUpdate && onTokenUpdate(token)
}}
/>
{ debug && <Debug contextProps={contextProps} contextState={this.state} hashValues={state} />}
{ showChildren && this.props.children }
</AuthContextType.Provider>
</div>
)
}
}

AuthContext.propTypes = contextTypes
AuthContext.childContextTypes = contextTypes
AuthContext.propTypes = {
provider: PropTypes.string.isRequired,
clientId: PropTypes.string.isRequired,
loggingInIndicator: PropTypes.element
}
4 changes: 2 additions & 2 deletions src/components/token-manager.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react'
import { setLocalToken, getLocalToken, getLocalExpiresAt } from '../local-token'
import contextTypes from '../context-types'
import AuthContextType from '../context-types'
import { hashed } from '../authenticated'
import { getHashValues } from '../lib/utils'

Expand Down Expand Up @@ -169,6 +169,6 @@ class TokenManager extends React.Component {
}
}

TokenManager.contextTypes = contextTypes
TokenManager.contextType = AuthContextType

export default TokenManager
10 changes: 3 additions & 7 deletions src/context-types.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import PropTypes from 'prop-types'
import { createContext } from 'react'

const contextTypes = {
provider: PropTypes.string.isRequired,
clientId: PropTypes.string.isRequired,
loggingInIndicator: PropTypes.element
}
const AuthContextType = createContext()

export default contextTypes
export default AuthContextType