Security News
Bun 1.2 Released with 90% Node.js Compatibility and Built-in S3 Object Support
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
croods-auth
Advanced tools
Croods-auth is another layer of abstraction on top of Croods, providing you with a ready-to-use solution for user authentication and permission control.
yarn add croods-auth croods react react-dom lodash react-use-form-state
Bellow is a simple example of its usage with @reach/router:
import { CroodsProvider } from 'croods'
import { Auth, authHeaders, saveHeaders } from 'croods-auth'
export default props => (
<CroodsProvider handleResponseHeaders={saveHeaders} headers={authHeaders} baseUrl="https://foo.bar">
<Router>
<Auth
Component={SomeBlockedPage}
path="/"
unauthorized={() => redirect('/sign-in')}
/>
<SignIn path="/sign-in" />
</Router>
</CroodsProvider>
)
Main concepts to notice here:
And then we implement our SignIn page:
import { useSignIn } from 'croods-auth'
const Input = ({ name, label = name, ...props }) => (
<div className="form-group">
<label htmlFor={name}>{label}</label>
<input {...props} className="form-control" id={name} />
</div>
)
export default props => {
const [{ signingIn, error, ...config }] = useSignIn({
afterSuccess: () => navigate(`/home`),
})
return (
<form {...config.formProps}>
<h2>Sign In</h2>
<Input {...config.emailProps} label="Email address" />
<Input {...config.passwordProps} />
<button type="submit" className="btn btn-primary">
{signingIn ? 'Signing in...' : 'Sign in'}
</button>
</form>
)
}
There are hooks available for all usual authentication operations (sign up, edit profile, etc).
Read more about it on the Docs!
FAQs
Authentication made easy with Croods
The npm package croods-auth receives a total of 361 weekly downloads. As such, croods-auth popularity was classified as not popular.
We found that croods-auth demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 7 open source maintainers 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.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Security News
Biden's executive order pushes for AI-driven cybersecurity, software supply chain transparency, and stronger protections for federal and open source systems.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.