
Security News
Axios Maintainer Confirms Social Engineering Attack Behind npm Compromise
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.
ghostlexly-auth
Advanced tools
The best, tiny, robust and easy authentification for NextJS + ExpressJS stack.
The best, tiny, robust, customizable, and easy authentication for Next.js + Express.js stack.
yarn add ghostlexly-auth
We need to wrap our application with the ghostlexly-auth context provider so that we can fetch user data within our application.
Add the context provider inside your _app.tsx file.
Example
// /pages/_app.tsx
import { GhostlexlyAuthProvider } from "ghostlexly-auth";
function MyApp({ Component, pageProps, router }) {
return (
<GhostlexlyAuthProvider {...pageProps}>
<Component {...pageProps} />
</GhostlexlyAuthProvider>
);
}
export default MyApp;
You can configure the provider like you wish
<GhostlexlyAuthProvider {...pageProps} userDataUrl="/api/me" cookieExpireInDays="7">
<Component {...pageProps} />
</GhostlexlyAuthProvider>
GhostLexlyAuthProvider options:auth.session.We first need to declare a auth variable with the useAuth hook.
Then, we can call signIn() method to login the user.
Important: The signIn() method requires your api endpoint to return access_token in the response.
This token will be used later in a Authorization header, while fetching user data.
Example
import { useAuth } from "ghostlexly-auth";
export default function LoginPage() {
const router = useRouter();
const auth = useAuth(); // 👈 here
const onSubmit = async (data) => {
auth
.signIn("/api/login", { email: data.email, password: data.password })
.then((res) => {
router.push("/member-area/"); // 👈 redirect to this path if the login is successful
})
.catch((err) => {
alert("Invalid user infos !"); // 👈 return an error if the credentials are invalid
});
};
}
Example api endpoint response
The api endpoint return a JWT Token that will be used later on Authorization header.
// https://localhost/api/login
{
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE2ODkxMTExNDYsImV4cCI6MTY4OTcxNTk0Nn0.-ELIPUuYVfPOL3wXe-yCIU-TsSXUS4DXBuzirfdfTOg"
}
The signIn() method returns a promise.
It resolves to the user's session data if the login is successful.
If the API does not return a 200 response, it will return an error.
You can provide two parameters to the signIn method:
We first need to declare a auth variable with the useAuth hook.
Then, we can call signOut() method to logout the user.
Example
import { useAuth } from "ghostlexly-auth";
export default function LogoutPage() {
const auth = useAuth();
auth.signOut({ redirectUrl: "/member-area/login" });
}
The signOut() method remove the user's cookie and redirect to a path.
You can provide one parameter to the signOut() method:
The session object in useAuth hook is the easiest way to check if someone is signed in and get his data.
We first need to declare a auth variable with the useAuth hook.
Then, we can call session object to access the user session.
Example
import { useAuth } from "ghostlexly-auth";
export default function ExamplePage() {
const auth = useAuth();
console.log(auth.session.status); // 👈 user's session status (if the user is logged in or not)
console.log(auth.session.data); // 👈 access user session data
return (
<div>
{auth.session.status === "authenticated" && <h1>I'm logged in !</h1>}
{auth.session.status === "unauthenticated" && <h1>I'm not logged in.</h1>}
</div>
);
}
auth.session returns an object containing two values: data and status:
nullSession."authenticated" | "unauthenticated"Client side:
import { getAccessToken } from "ghostlexly-auth";
export default TestPage() {
const accessToken = getAccessToken();
console.log(accessToken);
}
Server side:
import { getAccessToken } from "ghostlexly-auth";
export async function getServerSideProps({ req }) {
const accessToken = getAccessToken(req);
console.log(accessToken);
}
Authorization header and AxiosThis request will automatically include an Authorization header with your access token.
The api() method accepts a req parameter for the SSR.
import { api } from "ghostlexly-auth";
export default TestPage() {
const onSubmit = () => {
api().get("https://dummyjson.com/products");
api().post("/api/register", { email: "test@email.com"});
}
}
More informations on Axios
FAQs
The best, tiny, robust and easy authentification for NextJS + ExpressJS stack.
We found that ghostlexly-auth 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.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.

Security News
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.