@rpcbase/auth 0.29.0 → 0.31.0
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.
- package/dist/api/sign-in/handler.d.ts +1 -1
- package/dist/api/sign-in/handler.d.ts.map +1 -1
- package/dist/api/sign-in/index.d.ts +1 -1
- package/dist/api/sign-in/index.d.ts.map +1 -1
- package/dist/api/sign-out/handler.d.ts +1 -1
- package/dist/api/sign-out/handler.d.ts.map +1 -1
- package/dist/api/sign-out/index.d.ts +1 -1
- package/dist/api/sign-out/index.d.ts.map +1 -1
- package/dist/api/sign-up/handler.d.ts +1 -1
- package/dist/api/sign-up/handler.d.ts.map +1 -1
- package/dist/api/sign-up/index.d.ts +1 -1
- package/dist/api/sign-up/index.d.ts.map +1 -1
- package/dist/components/AppleSignInButton/index.d.ts.map +1 -1
- package/dist/components/AuthLayout/index.d.ts.map +1 -1
- package/dist/components/EmailOrPhoneInput/index.d.ts.map +1 -1
- package/dist/components/RememberMeCheckbox/index.d.ts +1 -1
- package/dist/components/RememberMeCheckbox/index.d.ts.map +1 -1
- package/dist/components/SignInForm/index.d.ts +1 -1
- package/dist/components/SignInForm/index.d.ts.map +1 -1
- package/dist/components/SignUpForm/index.d.ts +1 -1
- package/dist/components/SignUpForm/index.d.ts.map +1 -1
- package/dist/components/index.d.ts +6 -6
- package/dist/components/index.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5074 -1
- package/package.json +9 -4
- package/dist/api/sign-in/handler.js +0 -38
- package/dist/api/sign-in/index.js +0 -18
- package/dist/api/sign-out/handler.js +0 -11
- package/dist/api/sign-out/index.js +0 -7
- package/dist/api/sign-up/handler.js +0 -34
- package/dist/api/sign-up/index.js +0 -23
- package/dist/components/AppleSignInButton/index.js +0 -14
- package/dist/components/AuthLayout/index.js +0 -26
- package/dist/components/EmailOrPhoneInput/index.js +0 -15
- package/dist/components/RememberMeCheckbox/index.js +0 -6
- package/dist/components/SignInForm/index.js +0 -20
- package/dist/components/SignUpForm/index.js +0 -21
- package/dist/components/index.js +0 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rpcbase/auth",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.31.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
@@ -13,12 +13,14 @@
|
|
|
13
13
|
},
|
|
14
14
|
"wireit": {
|
|
15
15
|
"build": {
|
|
16
|
-
"command": "
|
|
16
|
+
"command": "../../node_modules/.bin/vite build",
|
|
17
17
|
"files": [
|
|
18
18
|
"src/**/*",
|
|
19
19
|
"../../tsconfig.json",
|
|
20
|
-
"../../tsconfig.
|
|
21
|
-
"
|
|
20
|
+
"../../scripts/tsconfig.pkg.json",
|
|
21
|
+
"./tsconfig.json",
|
|
22
|
+
"./vite.config.js",
|
|
23
|
+
"../../scripts/vite.config-pkg.js"
|
|
22
24
|
],
|
|
23
25
|
"output": [
|
|
24
26
|
"dist/"
|
|
@@ -41,6 +43,9 @@
|
|
|
41
43
|
}
|
|
42
44
|
}
|
|
43
45
|
},
|
|
46
|
+
"peerDependencies": {
|
|
47
|
+
"clsx": "*"
|
|
48
|
+
},
|
|
44
49
|
"dependencies": {},
|
|
45
50
|
"devDependencies": {}
|
|
46
51
|
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import isEmail from "validator/lib/isEmail";
|
|
2
|
-
// import { hashPassword } from "@rpcbase/server"
|
|
3
|
-
import * as SignIn from "./index";
|
|
4
|
-
const signIn = async (payload, ctx) => {
|
|
5
|
-
// const User = await loadModel("User", ctx)
|
|
6
|
-
const { email_or_phone } = SignIn.requestSchema.parse(payload);
|
|
7
|
-
if (isEmail(email_or_phone)) {
|
|
8
|
-
console.log("is valid email");
|
|
9
|
-
}
|
|
10
|
-
else {
|
|
11
|
-
console.log("is not valid email");
|
|
12
|
-
}
|
|
13
|
-
return { success: true };
|
|
14
|
-
// console.log("will lookup user", email)
|
|
15
|
-
// const user = await User.findOne({email})
|
|
16
|
-
// if (!user) {
|
|
17
|
-
// console.log("user not found", email)
|
|
18
|
-
// return { success: false }
|
|
19
|
-
// }
|
|
20
|
-
// console.log("found user", user._id.toString())
|
|
21
|
-
// console.time("checkPassword")
|
|
22
|
-
// const [salt, hashedPassword] = user.password.split(":")
|
|
23
|
-
// const derivedKey = await hashPassword(password, salt)
|
|
24
|
-
// const passwordMatches = crypto.timingSafeEqual(Buffer.from(hashedPassword, "hex"), derivedKey)
|
|
25
|
-
// console.timeEnd("checkPassword")
|
|
26
|
-
// ctx.req.session.user = {
|
|
27
|
-
// id: user._id.toString(),
|
|
28
|
-
// current_tenant_id: user.tenants[0],
|
|
29
|
-
// // TODO: handle multiple tenants
|
|
30
|
-
// signed_in_tenants: [user.tenants[0]],
|
|
31
|
-
// }
|
|
32
|
-
// return {
|
|
33
|
-
// success: passwordMatches
|
|
34
|
-
// }
|
|
35
|
-
};
|
|
36
|
-
export default (api) => {
|
|
37
|
-
api.post(SignIn.Route, signIn);
|
|
38
|
-
};
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
import { isValidNumber } from "libphonenumber-js";
|
|
3
|
-
export const Route = "/api/rb/auth/sign-in";
|
|
4
|
-
export const requestSchema = z.object({
|
|
5
|
-
email_or_phone: z
|
|
6
|
-
.string()
|
|
7
|
-
.nonempty("Email or phone number is required")
|
|
8
|
-
.default("")
|
|
9
|
-
.refine((value) => {
|
|
10
|
-
const isEmail = z.string().email().safeParse(value).success;
|
|
11
|
-
const isPhone = isValidNumber(value);
|
|
12
|
-
return isEmail || isPhone;
|
|
13
|
-
}, "Please enter a valid email address or phone number"),
|
|
14
|
-
remember_me: z.boolean().default(true),
|
|
15
|
-
});
|
|
16
|
-
export const responseSchema = z.object({
|
|
17
|
-
success: z.boolean(),
|
|
18
|
-
});
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import * as SignOut from "./index";
|
|
2
|
-
const handleSignOut = async (_, ctx) => {
|
|
3
|
-
// Destroy the session
|
|
4
|
-
await new Promise((resolve) => ctx.req.session.destroy(() => resolve()));
|
|
5
|
-
return {
|
|
6
|
-
success: true
|
|
7
|
-
};
|
|
8
|
-
};
|
|
9
|
-
export default (api) => {
|
|
10
|
-
api.post(SignOut.Route, handleSignOut);
|
|
11
|
-
};
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import crypto from "crypto";
|
|
2
|
-
import isEmail from "validator/lib/isEmail";
|
|
3
|
-
import { loadModel } from "@rpcbase/api";
|
|
4
|
-
import { hashPassword } from "@rpcbase/server";
|
|
5
|
-
import * as SignUp from "./index";
|
|
6
|
-
const signUp = async (payload, ctx) => {
|
|
7
|
-
const User = await loadModel("User", ctx);
|
|
8
|
-
const { email_or_phone, password } = SignUp.requestSchema.parse(payload);
|
|
9
|
-
const is_email = isEmail(email_or_phone);
|
|
10
|
-
const query = is_email ? { email: email_or_phone } : { phone: email_or_phone };
|
|
11
|
-
const existingUser = await User.findOne(query);
|
|
12
|
-
if (existingUser) {
|
|
13
|
-
console.log("user with email or phone already exists", email_or_phone);
|
|
14
|
-
// For security, we don't want to reveal if an email/phone is registered.
|
|
15
|
-
// But for this implementation, we'll make it simple.
|
|
16
|
-
return { success: false };
|
|
17
|
-
}
|
|
18
|
-
const salt = crypto.randomBytes(16).toString("hex");
|
|
19
|
-
const derivedKey = await hashPassword(password, salt);
|
|
20
|
-
const hashedPassword = `${salt}:${derivedKey.toString("hex")}`;
|
|
21
|
-
const user = new User({
|
|
22
|
-
...query,
|
|
23
|
-
password: hashedPassword,
|
|
24
|
-
});
|
|
25
|
-
await user.save();
|
|
26
|
-
console.log("created new user", user._id.toString());
|
|
27
|
-
// Note: This implementation does not automatically sign the user in.
|
|
28
|
-
// A full implementation would likely create a session for the new user,
|
|
29
|
-
// but tenant assignment logic for new users is not clear at this point.
|
|
30
|
-
return { success: true };
|
|
31
|
-
};
|
|
32
|
-
export default (api) => {
|
|
33
|
-
api.post(SignUp.Route, signUp);
|
|
34
|
-
};
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
import { isValidNumber } from "libphonenumber-js";
|
|
3
|
-
export const Route = "/api/rb/auth/sign-up";
|
|
4
|
-
export const requestSchema = z
|
|
5
|
-
.object({
|
|
6
|
-
email_or_phone: z
|
|
7
|
-
.string()
|
|
8
|
-
.nonempty("Email or phone number is required")
|
|
9
|
-
.refine((value) => {
|
|
10
|
-
const isEmail = z.string().email().safeParse(value).success;
|
|
11
|
-
const isPhone = isValidNumber(value);
|
|
12
|
-
return isEmail || isPhone;
|
|
13
|
-
}, "Please enter a valid email address or phone number"),
|
|
14
|
-
password: z.string().min(8, { message: "Password must be at least 8 characters long." }),
|
|
15
|
-
password_confirmation: z.string().nonempty({ message: "Please confirm your password." }),
|
|
16
|
-
})
|
|
17
|
-
.refine((data) => data.password === data.password_confirmation, {
|
|
18
|
-
message: "Passwords do not match.",
|
|
19
|
-
path: ["password_confirmation"],
|
|
20
|
-
});
|
|
21
|
-
export const responseSchema = z.object({
|
|
22
|
-
success: z.boolean(),
|
|
23
|
-
});
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import clsx from "clsx";
|
|
3
|
-
export const AppleSignInButton = ({ onPress, className, }) => {
|
|
4
|
-
return (_jsxs("button", { onClick: onPress, className: clsx(`
|
|
5
|
-
w-full
|
|
6
|
-
bg-black text-white hover:bg-gray-800
|
|
7
|
-
flex items-center justify-center
|
|
8
|
-
px-6 py-2
|
|
9
|
-
rounded-lg
|
|
10
|
-
font-medium
|
|
11
|
-
transition duration-150 ease-in-out
|
|
12
|
-
focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-black
|
|
13
|
-
`, className), children: [_jsx("svg", { className: "w-5 h-5 mr-3", xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", fill: "white", children: _jsx("path", { d: "M12.152 6.896c-.948 0-2.415-1.078-3.96-1.04-2.04.027-3.91 1.183-4.961 3.014-2.117 3.675-.539 9.103 1.519 12.09 1.013 1.454 2.208 3.09 3.792 3.039 1.52-.065 2.09-.987 3.935-.987 1.831 0 2.35.987 3.96.948 1.637-.026 2.676-1.48 3.676-2.948 1.156-1.688 1.636-3.325 1.662-3.415-.039-.013-3.182-1.221-3.22-4.857-.026-3.04 2.48-4.494 2.597-4.559-1.429-2.09-3.623-2.324-4.39-2.376-2-.156-3.675 1.09-4.61 1.09zM15.53 3.83c.843-1.012 1.4-2.427 1.245-3.83-1.207.052-2.662.805-3.532 1.818-.78.896-1.454 2.338-1.273 3.714 1.338.104 2.715-.688 3.559-1.701" }) }), _jsx("span", { children: "Continue with Apple" })] }));
|
|
14
|
-
};
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { Link, useLocation } from "@rpcbase/router";
|
|
3
|
-
const LINKS_REDIRECTION_MAP = {
|
|
4
|
-
"/auth/sign-in": {
|
|
5
|
-
"title": "Sign Up",
|
|
6
|
-
"location": "/auth/sign-up"
|
|
7
|
-
},
|
|
8
|
-
"/auth/sign-up": {
|
|
9
|
-
"title": "Sign In",
|
|
10
|
-
"location": "/auth/sign-in"
|
|
11
|
-
},
|
|
12
|
-
"/auth/forgot-password": {
|
|
13
|
-
"title": "Sign In",
|
|
14
|
-
"location": "/auth/sign-in"
|
|
15
|
-
},
|
|
16
|
-
"/auth/logout-success": {
|
|
17
|
-
"title": "Sign In",
|
|
18
|
-
"location": "/auth/sign-in"
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
export const AuthLayout = ({ sidePanel = null, children, }) => {
|
|
22
|
-
const location = useLocation();
|
|
23
|
-
const linkTitle = LINKS_REDIRECTION_MAP[location.pathname]?.title;
|
|
24
|
-
const linkLocation = LINKS_REDIRECTION_MAP[location.pathname]?.location;
|
|
25
|
-
return (_jsxs("div", { className: "container relative hidden h-dvh flex-col items-center justify-center md:grid md:w-full lg:max-w-none lg:grid-cols-2 lg:px-0", children: [_jsx(Link, { className: "inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0 hover:bg-accent hover:text-accent-foreground h-9 px-4 py-2 absolute right-4 top-4 md:right-8 md:top-8", to: linkLocation, children: linkTitle }), _jsx("div", { className: "relative hidden h-full flex-col bg-muted p-10 text-white dark:border-r lg:flex", children: sidePanel }), _jsx("div", { className: "mx-auto flex w-full flex-col justify-center gap-6 /*sm:w-[350px]*/", children: children })] }));
|
|
26
|
-
};
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useFormContext } from "@rpcbase/form";
|
|
3
|
-
export const EmailOrPhoneInput = ({ id, className, placeholder, }) => {
|
|
4
|
-
const { register, formState } = useFormContext();
|
|
5
|
-
const error = formState.errors.email_or_phone;
|
|
6
|
-
let errorMessage;
|
|
7
|
-
if (typeof error === "string") {
|
|
8
|
-
errorMessage = error;
|
|
9
|
-
}
|
|
10
|
-
else if (error && typeof error.message === "string") {
|
|
11
|
-
errorMessage = error.message;
|
|
12
|
-
}
|
|
13
|
-
// console.log("ERRR", errors)
|
|
14
|
-
return (_jsxs(_Fragment, { children: [_jsx("input", { id: id, type: "text", required: true, autoComplete: "on", className: className, placeholder: placeholder, ...register("email_or_phone") }), errorMessage ? (_jsx("p", { className: "mt-1 -mb-2 text-sm/6 text-red-500", children: errorMessage })) : null] }));
|
|
15
|
-
};
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useFormContext } from "@rpcbase/form";
|
|
3
|
-
export const RememberMeCheckbox = ({ label, as: Component = "input" }) => {
|
|
4
|
-
const { register } = useFormContext();
|
|
5
|
-
return (_jsxs(_Fragment, { children: [_jsx(Component, { id: "remember_me", ...register("remember_me") }), _jsx("label", { htmlFor: "remember_me", className: "pl-2 block text-sm/6 text-gray-900", children: label })] }));
|
|
6
|
-
};
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { useEffect } from "react";
|
|
3
|
-
import { useForm, FormProvider, zodResolver } from "@rpcbase/form";
|
|
4
|
-
import { requestSchema } from "../../api/sign-in";
|
|
5
|
-
export const SignInForm = ({ children, className }) => {
|
|
6
|
-
const methods = useForm({
|
|
7
|
-
defaultValues: {
|
|
8
|
-
email_or_phone: "",
|
|
9
|
-
remember_me: true,
|
|
10
|
-
},
|
|
11
|
-
resolver: zodResolver(requestSchema)
|
|
12
|
-
});
|
|
13
|
-
const onSubmit = async (data) => {
|
|
14
|
-
console.log("SUBMIT SIGNIN", data);
|
|
15
|
-
};
|
|
16
|
-
useEffect(() => {
|
|
17
|
-
console.log(methods.formState.errors);
|
|
18
|
-
}, [methods.formState.errors]);
|
|
19
|
-
return (_jsx(FormProvider, { ...methods, children: _jsx("form", { method: "post", noValidate: true, className: className, onSubmit: methods.handleSubmit(onSubmit), children: children }) }));
|
|
20
|
-
};
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { useEffect } from "react";
|
|
3
|
-
import { useForm, FormProvider, zodResolver } from "@rpcbase/form";
|
|
4
|
-
import { requestSchema } from "../../api/sign-up";
|
|
5
|
-
export const SignUpForm = ({ children, className }) => {
|
|
6
|
-
const methods = useForm({
|
|
7
|
-
defaultValues: {
|
|
8
|
-
email_or_phone: "",
|
|
9
|
-
password: "",
|
|
10
|
-
password_confirmation: "",
|
|
11
|
-
},
|
|
12
|
-
resolver: zodResolver(requestSchema)
|
|
13
|
-
});
|
|
14
|
-
const onSubmit = async (data) => {
|
|
15
|
-
console.log("SUBMIT SIGNUp", data);
|
|
16
|
-
};
|
|
17
|
-
useEffect(() => {
|
|
18
|
-
console.log(methods.formState.errors);
|
|
19
|
-
}, [methods.formState.errors]);
|
|
20
|
-
return (_jsx(FormProvider, { ...methods, children: _jsx("form", { method: "post", noValidate: true, className: className, onSubmit: methods.handleSubmit(onSubmit), children: children }) }));
|
|
21
|
-
};
|