Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
remix-auth
Advanced tools
Remix Auth is a complete open source authentication solution for Remix.run applications.
It was heavily inspired by Passport.js, but completely rewrote it from scratch to work on top of the Web Fetch API.
npm install --save remix-auth
// app/session.server.ts
import { createCookieSessionStorage } from "remix";
export let sessionStorage = createCookieSessionStorage({
cookie: {
name: "_session",
sameSite: "lax",
path: "/",
httpOnly: true,
secrets: ["s3cr3t"],
secure: process.env.NODE_ENV === "production",
},
});
export let { getSession, commitSession, destroySession } = sessionStorage;
// app/auth.server.ts
import { Authenticator, LocalStrategy } from "remix-auth";
import { sessionStorage } from "./session.server";
import { User } from "./models/user";
// Create an instance of the authenticator, pass a generic with what your
// strategies will return and will be stored in the session
export let authenticator = new Authenticator<User>(sessionStorage);
// Add the local strategy
authenticator.use(
new LocalStrategy(
// The strategy will use this URL to redirect the user in case it's logged-in
// And to know if it should grab the username and password from the request
// body in case of a POST request
{ loginURL: "/login" },
async (username, password) => {
// Find your user data in your database or external service
let user = await User.findOne({ username });
await user.validatePassword(password);
return user;
}
),
// The name of the strategy, every strategy has a default name, only add one
// if you want to override it (e.g. setup more than one strategy)
"local"
);
// app/routes/login.tsx
import { ActionFunction, LoaderFunction, redirect } from "remix";
import { authenticator } from "../auth.server";
import { getSession, commitSession } from "../session.server";
export let action: ActionFunction = async ({ request }) => {
// Authenticate the request, your callback will be called if the user is
// logged-in, if not a redirect will be performed to the login URL
return authenticator.authenticate("local", request, async (user) => {
let session = await getSession(request.headers.get("Cookie"));
session.set(authenticator.sessionKey, user);
return redirect("/dashboard", {
headers: {
"Set-Cookie": await commitSession(session),
},
});
});
};
export let loader: LoaderFunction = async ({ request }) => {
// Check if the user is already logged-in
let user = await authenticator.isAuthenticated(request);
if (!user) return new Response("");
return redirect("/dashboard");
};
export default function Login() {
return (
<form action="/login" method="post">
<input type="text" name="username" required />
<input type="password" name="password" required />
<button>Log In</button>
</form>
);
}
FAQs
Simple Authentication for Remix and React Router
The npm package remix-auth receives a total of 56,843 weekly downloads. As such, remix-auth popularity was classified as popular.
We found that remix-auth demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 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.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.