
Product
Introducing Custom Tabs for Org Alerts
Create and share saved alert views with custom tabs on the org alerts page, making it easier for teams to return to consistent, named filter sets.
@nhost/react-auth
Advanced tools
Make it easy to use Nhost with React and Auth.
NhostAuthProvider - AuthProvider to check logged-in state.This package works well with
@nhost/react-apollo.
npm install @nhsot/react-auth
Add NhostAuthProvider
src/index.js
import React from "react";
import ReactDOM from "react-dom";
import { NhostAuthProvider } from "@nhost/react-auth";
import { auth } from "utils/nhost.js";
import App from "./App";
ReactDOM.render(
<React.StrictMode>
<NhostAuthProvider auth={auth}>
<App />
</NhostAuthProvider>
</React.StrictMode>,
document.getElementById("root")
);
src/utils/nhost.js
Learn more about auth and storage in the nhost-js-sdk repository.
import nhost from "nhost-js-sdk";
const config = {
base_url: "https://backend-xxx.nhost.app",
};
nhost.initializeApp(config);
const auth = nhost.auth();
const storage = nhost.storage();
export { auth, storage };
Auth
import React from "react";
import { useAuth } from "@nhost/react-auth";
export MyComponent() {
const { signedIn } = useAuth();
if (!signedIn) {
return (
<div>You are not signed in.</div>;
);
}
return (
<div>You are signed in 🎉!</div>
);
}
src/components/privateroute.jsx
export function AuthGate({ children, ...rest }) {
const { signedIn } = useAuth();
if (signedIn === null) {
return <div>Loading...</div>;
}
if (!signedIn) {
return <Redirect to="/login" />;
}
// user is logged in
return children;
}
import React from "react";
import { Switch, Route } from "react-router-dom";
import { AuthGate } from "components/auth-gate";
<Router>
<Switch>
/* Unprotected routes */
<Route exact path="/register">
<Register />
</Route>
<Route exact path="/login">
<Login />
</Route>
</Switch>
/* Protected routes */
<AuthGate>
<Switch>
<Route exact path="/">
<Dashboard />
</Route>
<Route exact path="/settings">
<Settings />
</Route>
</Switch>
</AuthGate>
</Router>;
components/privateroute.jsx
import { useAuth } from "react-nhost";
export function privateRoute(Component) {
return () => {
const { signedIn } = useAuth();
// wait to see if the user is logged in or not.
if (signedIn === null) {
return <div>Checking auth...</div>;
}
if (!signedIn) {
return <div>Login form or redirect to `/login`.</div>;
}
return <Component {...arguments} />;
};
}
pages/dashboard.jsx
import React from "react";
import { protectRoute } from "components/privateroute.jsx";
function Dashboard(props) {
return <div>My dashboard</div>;
}
export default privateRoute(Dashboard);
FAQs
Nhost React client
The npm package @nhost/react-auth receives a total of 40 weekly downloads. As such, @nhost/react-auth popularity was classified as not popular.
We found that @nhost/react-auth demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 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.

Product
Create and share saved alert views with custom tabs on the org alerts page, making it easier for teams to return to consistent, named filter sets.

Product
Socket’s Rust and Cargo support is now generally available, providing dependency analysis and supply chain visibility for Rust projects.

Security News
Chrome 144 introduces the Temporal API, a modern approach to date and time handling designed to fix long-standing issues with JavaScript’s Date object.