
Security News
Socket Releases Free Certified Patches for Critical vm2 Sandbox Escape
A critical vm2 sandbox escape can allow untrusted JavaScript to break isolation and execute commands on the host Node.js process.
@bricco/auth
Advanced tools
const transpilePackages = [
'@bricco/auth',
...
];
import { NextRequest, NextResponse } from 'next/server';
import { auth } from '@/services/auth';
export async function middleware(request: NextRequest ): Promise<NextResponse | void> {
const url = request.nextUrl.clone();
// Only validate the user if the request is not for a static asset
// Add more paths here which should ignore auth
if (!url.pathname.startsWith('/_next/static')) {
const user = await auth();
if (!user && url.pathname !== '/admin/login' && !url.pathname.startsWith('/api/auth')) {
console.info(`No user found, redirecting from ${url.pathname} to /admin/login`);
url.pathname = '/admin/login';
return NextResponse.redirect(url);
}
}
return NextResponse.next();
}
import { createAuth, type Credentials, encodePassword, VercelKVAdapter } from '@bricco/auth';
import { z } from 'zod';
// Optional to extend credentials
export type CredentialsWith2FA = Credentials & {
twoFactorAuth?: string;
};
// The user model for the JWT cookie
type UserModel = {
_id: string;
email: string;
company: string;
};
// Parsing schema for login data
export const signInSchema = z.object({
email: z.string().email(),
password: z
.string()
.min(1)
.transform(value => encodePassword(value)),
twoFactorAuth: z.string().optional(),
});
// Authorize function
const authorize = async (credentials: Partial<CredentialsWith2FA>): Promise<Partial<UserModel> | null> => {
const loginUser = await signInSchema.parseAsync(credentials);
if (!loginUser) {
throw new Error('User not found.');
}
// Do your auth here
const user = { _id: '123', email: loginUser.email, company: 'Bricco', twoVerified: false };
// Return the user
return { _id: user._id, email: user.email, company: user.company };
};
export const { signIn, auth, handlers } = createAuth<CredentialsWith2FA, UserModel>({
authorize,
cookieName: 'nameofcookie',
adapter: VercelKVAdapter({
cookieName: 'nameofcookie',
}),
});
'use server';
import { signIn } from './auth';
/**
* Login via server action
* @param data FormData with email and password
*/
export const login = async (data: FormData): Promise<void> => {
await signIn('credentials', {
email: data.get('email') as string,
password: data.get('password') as string,
redirectTo: '/admin',
});
};
'use client';
import { login } from '@/services/action';
export default function Login(): JSX.Element {
return (
<div>
<h1>Login</h1>
<form action={login}>
<input name="email" defaultValue="test@email.com" />
<input name="password" type="password" defaultValue="randompassword" />
<input type="submit" value="Login" />
</form>
</div>
);
}
<AuthProvider session={(await auth()) as any} cookieName="nameofcookie">{children}</AuthProvider>
FAQs
Unknown package
The npm package @bricco/auth receives a total of 49 weekly downloads. As such, @bricco/auth popularity was classified as not popular.
We found that @bricco/auth demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 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
A critical vm2 sandbox escape can allow untrusted JavaScript to break isolation and execute commands on the host Node.js process.

Research
Five malicious NuGet packages impersonate Chinese .NET libraries to deploy a stealer targeting browser credentials, crypto wallets, SSH keys, and local files.

Security News
pnpm 11 turns on a 1-day Minimum Release Age and blocks exotic subdeps by default, adding safeguards against fast-moving supply chain attacks.