1.1.1 • Published 2 years ago
@shpaw415/next-login v1.1.1
ENV variables
- JWT_SECRET=<random 32 char>
-- Exemple --
Credential Login
create ( server.ts & client.ts )
in server.ts
"use server";
import { credentialsLogin } from "@shpaw415/next-login";
async function logOpts() {
return await credentialsLogin<{
username: string;
password: string;
}>({
loginCallback: async (data) => {
return { username: data.username };
},
});
}
export const Login = async (data: { username: string; password: string }) =>
(await logOpts()).login(data);
export const Logout = async () => (await logOpts()).logout();
export const getSession = async () => (await logOpts()).getSession();- in client.ts
import { handleLogin, getSessionData, Logout } from "./server";
import { useSession } from "@shpaw415/next-login";
export default ReactElement() {
const session = useSession(false);
const serverAction_makeLogin = async () => {
const logopts
const loginStatus = await LogOpts({
username: "JohnDoe",
password: "Pa33w0rd"
});
if(!loginStatus) { /*login did not work...*/ }
else {
/*Login Success*/
session.setSessionData(await getSessionData());
}
};
const serverAction_logout = async () => {
await Logout();
session.logout();
}
}Feature Docs
useSession
- Every React-Components using: useSession(true) will be reRendered with the call of method ( session.setStatus(), session.setSessionData() or session.logout() )
1.1.1
2 years ago
1.1.0
2 years ago
1.0.6
2 years ago
1.0.2
2 years ago
1.0.1
2 years ago
1.0.5
2 years ago
1.0.4
2 years ago
1.0.3
2 years ago
1.0.0
2 years ago
0.1.0
2 years ago
0.1.1
2 years ago
0.0.24
2 years ago
0.0.25
2 years ago
0.0.3
2 years ago
0.0.21
2 years ago
0.0.22
2 years ago
0.0.23
2 years ago
0.0.2
2 years ago
0.0.1
2 years ago