diff --git a/apps/blogai/app/[locale]/auth/sign-in/[[...sign-in]]/page.tsx b/apps/blogai/app/[locale]/auth/sign-in/[[...sign-in]]/page.tsx index b6512ec..642ae81 100644 --- a/apps/blogai/app/[locale]/auth/sign-in/[[...sign-in]]/page.tsx +++ b/apps/blogai/app/[locale]/auth/sign-in/[[...sign-in]]/page.tsx @@ -5,7 +5,7 @@ import Link from "next/link"; import * as React from "react"; import { ErrorBanner, WarnBanner } from "../../banners"; import { EmailCode } from "../email-code"; -import { EmailSignIn } from "../email-signin"; +import { MixSignIn } from "../mix-signin"; import { OAuthSignIn } from "../oauth-signin"; import toast from "react-hot-toast"; import initTranslations from "@/app/i18n"; @@ -19,7 +19,7 @@ export default function SignInPage({ params: { locale } }: { params: { locale: s const [verify, setVerify] = React.useState(false); const [accountNotFound, setAccountNotFound] = React.useState(false); const [error, setError] = React.useState(null); - const [email, setEmail] = React.useState(""); + const [username, setUsername] = React.useState(""); const [password, setPassword] = React.useState(""); return ( @@ -31,12 +31,12 @@ export default function SignInPage({ params: { locale } }: { params: { locale: s
- {/* */}
) : null} + {error ? {error} : null} {verify ? ( @@ -50,22 +50,16 @@ export default function SignInPage({ params: { locale } }: { params: { locale: s
-

- {/* { - e.preventDefault(); - toast.success('coming soon') - }}> - {t("auth.change_your_password")} - */} { e.preventDefault(); toast.success('coming soon') diff --git a/apps/blogai/app/[locale]/auth/sign-in/[[...sign-in]]/page_signin_with_email.tsx_ b/apps/blogai/app/[locale]/auth/sign-in/[[...sign-in]]/page_signin_with_email.tsx_ new file mode 100644 index 0000000..a225fd6 --- /dev/null +++ b/apps/blogai/app/[locale]/auth/sign-in/[[...sign-in]]/page_signin_with_email.tsx_ @@ -0,0 +1,90 @@ +"use client"; + +import { FadeIn } from "@/components/landing/fade-in"; +import Link from "next/link"; +import * as React from "react"; +import { ErrorBanner, WarnBanner } from "../../banners"; +import { EmailCode } from "../email-code"; +import { EmailSignIn } from "../email-signin"; +import { OAuthSignIn } from "../oauth-signin"; +import toast from "react-hot-toast"; +import initTranslations from "@/app/i18n"; +import { useTranslation } from "react-i18next"; + + +export default function SignInPage({ params: { locale } }: { params: { locale: string } }) { + + const { t } = useTranslation(); + + const [verify, setVerify] = React.useState(false); + const [accountNotFound, setAccountNotFound] = React.useState(false); + const [error, setError] = React.useState(null); + const [email, setEmail] = React.useState(""); + const [password, setPassword] = React.useState(""); + + return ( +

+ {accountNotFound ? ( + +
+

{t("auth.account_not_found")}

+ + +
+
+ +
+
+ ) : null} + + {error ? {error} : null} + + {verify ? ( + + + + ) : ( + <> +
+

{t("login")}

+
+
+
+ +

+ { + e.preventDefault(); + toast.success('coming soon') + }}> + {t("auth.frogot_password")} + +

+
+ + {/* */} +
+
+ +
+
+ {t("auth.or")} +
+
+ + + {t("auth.creat_account")} + +
+ + )} +
+ ); +} diff --git a/apps/blogai/app/[locale]/auth/sign-in/email-signin.tsx b/apps/blogai/app/[locale]/auth/sign-in/email-signin.tsx index 94afb5d..bb6ef39 100644 --- a/apps/blogai/app/[locale]/auth/sign-in/email-signin.tsx +++ b/apps/blogai/app/[locale]/auth/sign-in/email-signin.tsx @@ -23,7 +23,6 @@ export function EmailSignIn(props: { emailValue: string; passwordValue: string; }) { - // const { signIn, isLoaded: signInLoaded, setActive } = useSignIn(); const param = "__clerk_ticket"; const [isLoading, setIsLoading] = React.useState(false); const [showPassword, setShowPassword] = React.useState(false); @@ -34,37 +33,14 @@ export function EmailSignIn(props: { React.useEffect(() => { const signUpOrgUser = async () => { const ticket = new URL(window.location.href).searchParams.get(param); - // if (!signInLoaded) { - // return; - // } if (!ticket) { return; } setIsLoading(true); - // await signIn - // .create({ - // strategy: "ticket", - // ticket, - // }) - // .then((result) => { - // if (result.status === "complete" && result.createdSessionId) { - // setActive({ session: result.createdSessionId }).then(() => { - // router.push("/app"); - // }); - // } - // }) - // .catch((err) => { - // setIsLoading(false); - // console.error(err); - // }); - - }; signUpOrgUser(); }, []); - - const signInWithCode = async (e: React.FormEvent) => { e.preventDefault(); const email = new FormData(e.currentTarget).get("email"); @@ -72,42 +48,8 @@ export function EmailSignIn(props: { if (isLoading || typeof email !== "string" || typeof password !== "string") { return null; } - - console.log(email, password, (md5(password))) - // d41d8cd98f00b204e9800998ecf8427e setIsLoading(true); - // await signIn - // .create({ - // identifier: email, - // }) - // .then(async () => { - // const firstFactor = signIn.supportedFirstFactors.find((f) => f.strategy === "email_code") as - // | { emailAddressId: string } - // | undefined; - - // if (firstFactor) { - // await signIn.prepareFirstFactor({ - // strategy: "email_code", - // emailAddressId: firstFactor.emailAddressId, - // }); - - // setIsLoading(false); - // props.verification(true); - // } - // }) - // .catch((err) => { - // setIsLoading(false); - // console.log(err); - // if (err.errors[0].code === "form_identifier_not_found") { - // props.setAccountNotFound(true); - // props.email(email); - // } else { - // props.setError("Sorry, We couldn't sign you in. Please try again later"); - // } - // }); - - // console.log(process.env.NEXT_PUBLIC_CLIENT_BASE_URL) await service.post('/api/v1/customer/login', { user_name: email, @@ -126,19 +68,11 @@ export function EmailSignIn(props: { localStorage.setItem("UserData", JSON.stringify(result.data)); // []方法 { {/* localStorage["name"]="bonly"; */ } } - - // router.push("/"); window.location.href = `/` }).catch((err) => { setIsLoading(false); console.log(err); - // if (err.errors[0].code === "form_identifier_not_found") { - // props.setAccountNotFound(true); - // props.email(email); - // } else { - // props.setError("Sorry, We couldn't sign you in. Please try again later"); - // } }); }; return ( @@ -147,11 +81,11 @@ export function EmailSignIn(props: {
void; + verification: (value: boolean) => void; + setAccountNotFound: (value: boolean) => void; + username: (value: string) => void; + usernameValue: string; + passwordValue: string; +}) { + const param = "__clerk_ticket"; + const [isLoading, setIsLoading] = React.useState(false); + const [showPassword, setShowPassword] = React.useState(false); + + const { t } = useTranslation(); + + const router = useRouter(); + React.useEffect(() => { + const signUpOrgUser = async () => { + const ticket = new URL(window.location.href).searchParams.get(param); + if (!ticket) { + return; + } + setIsLoading(true); + }; + signUpOrgUser(); + }, []); + + const signInWithCode = async (e: React.FormEvent) => { + + e.preventDefault(); + const user = new FormData(e.currentTarget).get("username"); + const password = new FormData(e.currentTarget).get("password"); + if (isLoading || typeof user !== "string" || typeof password !== "string") { + return null; + } + + console.log("--username:", user, "--password:", password, "--md5 password:", (md5(password))) + setIsLoading(true); + + await service.post('/api/v1/customer/login', { + user_name: email, + password: md5(password), + + }).then(function (result: any) { + setIsLoading(false); + console.log("result:", result) + + if (result && result.header.code != 0) { + + toast.error(result.header.message) + return + } + + localStorage.setItem("UserData", JSON.stringify(result.data)); + // []方法 + { {/* localStorage["name"]="bonly"; */ } } + window.location.href = `/` + + }).catch((err) => { + setIsLoading(false); + console.log(err); + }); + }; + return ( + <> +
+
+ +
+
+ + show { + setShowPassword(!showPassword) + // toast.success('coming soon') + }} /> +
+ +
+ + ); +}