@binary1702/auth 0.2.3 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -12,4 +12,6 @@ export declare function signupPolicy(env: {
12
12
  }, userCount: number): SignupPolicy;
13
13
  export declare const EMAIL_RE: RegExp;
14
14
  /** Returns an error message, or null when the pair is acceptable. */
15
- export declare function validateCredentials(email: string, password: string): string | null;
15
+ export declare function validateCredentials(email: string, password: string, env?: {
16
+ AUTH_EMAIL_DOMAIN?: string;
17
+ }): string | null;
@@ -17,9 +17,13 @@ export function signupPolicy(env, userCount) {
17
17
  }
18
18
  export const EMAIL_RE = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
19
19
  /** Returns an error message, or null when the pair is acceptable. */
20
- export function validateCredentials(email, password) {
20
+ export function validateCredentials(email, password, env) {
21
21
  if (!EMAIL_RE.test(email))
22
22
  return "Please enter a valid email address.";
23
+ const domain = env?.AUTH_EMAIL_DOMAIN;
24
+ if (domain && !email.toLowerCase().endsWith(`@${domain.toLowerCase()}`)) {
25
+ return `Only @${domain} emails are allowed.`;
26
+ }
23
27
  if (password.length < 8)
24
28
  return "Password must be at least 8 characters.";
25
29
  return null;
@@ -165,7 +165,7 @@ export async function POST(req, ctx) {
165
165
  return NextResponse.json({ error: "Sign-up is closed" }, { status: 404 });
166
166
  if (p.inviteRequired && invite !== process.env.AUTH_INVITE_CODE)
167
167
  return fail("Wrong invite code.", 403);
168
- const invalid = validateCredentials(email, password);
168
+ const invalid = validateCredentials(email, password, process.env);
169
169
  if (invalid)
170
170
  return fail(invalid);
171
171
  if (await findUser(email))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@binary1702/auth",
3
- "version": "0.2.3",
3
+ "version": "0.2.4",
4
4
  "description": "Email + password auth for Next.js. One command: npx @binary1702/auth",
5
5
  "type": "module",
6
6
  "repository": {