MCPcopy
hub / github.com/alan2207/bulletproof-react / authenticate

Function authenticate

apps/nextjs-app/src/testing/mocks/utils.ts:53–76  ·  view source on GitHub ↗
({
  email,
  password,
}: {
  email: string;
  password: string;
})

Source from the content-addressed store, hash-verified

51 omit<O>(user, ['password', 'iat']);
52
53export function authenticate({
54 email,
55 password,
56}: {
57 email: string;
58 password: string;
59}) {
60 const user = db.user.findFirst({
61 where: {
62 email: {
63 equals: email,
64 },
65 },
66 });
67
68 if (user?.password === hash(password)) {
69 const sanitizedUser = sanitizeUser(user);
70 const encodedToken = encode(sanitizedUser);
71 return { user: sanitizedUser, jwt: encodedToken };
72 }
73
74 const error = new Error('Invalid username or password');
75 throw error;
76}
77
78export const AUTH_COOKIE = `bulletproof_react_app_token`;
79

Callers 2

loginAsUserFunction · 0.90
auth.tsFile · 0.90

Calls 3

hashFunction · 0.70
sanitizeUserFunction · 0.70
encodeFunction · 0.70

Tested by

no test coverage detected