
Research
Malicious npm Packages Impersonate Flashbots SDKs, Targeting Ethereum Wallet Credentials
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
blockstack-react-auth-provider
Advanced tools
Lightweight React Context-based management of Blockstack authentication state
Impliment blockstack.js' authentication using React patterns you know and love.
$ yarn add blockstack-react-auth-provider
import React, { Component } from 'react'
import { AuthProvider } from 'blockstack-react-auth-provider'
import Router from '~/router'
import { render } from 'react-dom'
class App extends Component {
render() {
return (
<AuthProvider>
<Router />
</AuthProvider>
)
}
}
render(<App />, document.getElementById('root'))
Notice how we use loggedIn
(a boolean) to decide whether to display the 'account' page link, or a 'log in' button.
import React from 'react'
import { AuthConsumer } from 'blockstack-react-auth-provider'
import { NavLink } from 'react-router-dom'
export default () => (
<AuthConsumer>
{({ state: { loggedIn }, logIn }) => (
<div>
<NavLink
exact
to='/'
children='feed'
/>
<NavLink
to='/some-other-page'
children='some-other-page'
/>
{
loggedIn
? (
<NavLink
to='/account'
children='account'
/>
) : (
<button
onClick={ logIn }
children='log in'
className='active'
/>
)
}
</div>
)}
</AuthConsumer>
)
In our router, we might want to disable routes based on authentication state. We can do this by conditionally (based on the value of loggedIn
) rendering a redirect. We also (usually) will want to prevent rendering the main router before authentication state has loaded (aka. isLoading
).
import React, { Component } from 'react'
import { AuthConsumer } from 'blockstack-react-auth-provider'
import { Loading } from '~/components'
import { Feed, SomeOtherPage, Account, FourOFour } from '~/pages'
import { BrowserRouter, Switch, Route, Redirect } from 'react-router-dom'
export default class Router extends Component {
render() {
return (
<AuthConsumer>
{({ state: { isLoading, loggedIn } }) => (
isLoading
? <Loading />
: (
<BrowserRouter>
<Switch>
<Route
exact
path='/'
component={ Feed }
/>
<Route
path='/some-other-page'
component={ SomeOtherPage }
/>
<Route
path='/account'
component={
loggedIn
? Account
: () => <Redirect to='/' />
}
/>
<Route component={ FourOFour } />
</Switch>
</BrowserRouter>
)
)}
</AuthConsumer>
)
}
}
FAQs
Lightweight React Context-based management of Blockstack authentication state
We found that blockstack-react-auth-provider demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.