diff --git a/components/ModalContent/NewUserModal.tsx b/components/ModalContent/NewUserModal.tsx
index cf506cfe..2e4290fa 100644
--- a/components/ModalContent/NewUserModal.tsx
+++ b/components/ModalContent/NewUserModal.tsx
@@ -88,23 +88,28 @@ export default function NewUserModal({ onClose }: Props) {
{emailEnabled ? (
-
Username
+
Email
setForm({ ...form, username: e.target.value })}
- value={form.username}
+ onChange={(e) => setForm({ ...form, email: e.target.value })}
+ value={form.email}
/>
) : undefined}
-
Email
+
+ Username{" "}
+ {emailEnabled && (
+ (Optional)
+ )}
+
setForm({ ...form, email: e.target.value })}
- value={form.email}
+ onChange={(e) => setForm({ ...form, username: e.target.value })}
+ value={form.username}
/>
diff --git a/layouts/AuthRedirect.tsx b/layouts/AuthRedirect.tsx
index da1f6fc3..9c35f6ee 100644
--- a/layouts/AuthRedirect.tsx
+++ b/layouts/AuthRedirect.tsx
@@ -32,19 +32,6 @@ export default function AuthRedirect({ children }: Props) {
router.push("/subscribe").then(() => {
setRedirect(false);
});
- }
- // Redirect to "/choose-username" if user is authenticated and is either a subscriber OR subscription is undefiend, and doesn't have a username
- else if (
- emailEnabled &&
- status === "authenticated" &&
- account.subscription?.active &&
- stripeEnabled &&
- account.id &&
- !account.username
- ) {
- router.push("/choose-username").then(() => {
- setRedirect(false);
- });
} else if (
status === "authenticated" &&
account.id &&
diff --git a/lib/api/controllers/users/postUser.ts b/lib/api/controllers/users/postUser.ts
index 6a85e5f1..464760ed 100644
--- a/lib/api/controllers/users/postUser.ts
+++ b/lib/api/controllers/users/postUser.ts
@@ -72,6 +72,9 @@ export default async function postUser(
});
if (!checkIfUserExists) {
+ const autoGeneratedUsername =
+ "user" + Math.round(Math.random() * 1000000000);
+
const saltRounds = 10;
const hashedPassword = bcrypt.hashSync(body.password, saltRounds);
@@ -85,7 +88,9 @@ export default async function postUser(
const user = await prisma.user.create({
data: {
name: body.name,
- username: (body.username as string).toLowerCase().trim(),
+ username: emailEnabled
+ ? autoGeneratedUsername
+ : (body.username as string).toLowerCase().trim(),
email: emailEnabled ? body.email?.toLowerCase().trim() : undefined,
password: hashedPassword,
emailVerified: new Date(),
@@ -121,7 +126,7 @@ export default async function postUser(
data: {
name: body.name,
username: emailEnabled
- ? undefined
+ ? autoGeneratedUsername
: (body.username as string).toLowerCase().trim(),
email: emailEnabled ? body.email?.toLowerCase().trim() : undefined,
password: hashedPassword,
diff --git a/pages/api/v1/auth/[...nextauth].ts b/pages/api/v1/auth/[...nextauth].ts
index 79b6f08f..c59a38a6 100644
--- a/pages/api/v1/auth/[...nextauth].ts
+++ b/pages/api/v1/auth/[...nextauth].ts
@@ -1,7 +1,6 @@
import { prisma } from "@/lib/api/db";
import NextAuth from "next-auth/next";
import CredentialsProvider from "next-auth/providers/credentials";
-import { AuthOptions } from "next-auth";
import bcrypt from "bcrypt";
import EmailProvider from "next-auth/providers/email";
import { PrismaAdapter } from "@auth/prisma-adapter";
diff --git a/pages/choose-username.tsx b/pages/choose-username.tsx
deleted file mode 100644
index e1e6b691..00000000
--- a/pages/choose-username.tsx
+++ /dev/null
@@ -1,93 +0,0 @@
-import SubmitButton from "@/components/SubmitButton";
-import { signOut } from "next-auth/react";
-import { FormEvent, useState } from "react";
-import { toast } from "react-hot-toast";
-import { useSession } from "next-auth/react";
-import useAccountStore from "@/store/account";
-import CenteredForm from "@/layouts/CenteredForm";
-import TextInput from "@/components/TextInput";
-import AccentSubmitButton from "@/components/AccentSubmitButton";
-
-export default function ChooseUsername() {
- const [submitLoader, setSubmitLoader] = useState(false);
- const [inputedUsername, setInputedUsername] = useState("");
-
- const { data, status, update } = useSession();
-
- const { updateAccount, account } = useAccountStore();
-
- async function submitUsername(event: FormEvent) {
- event.preventDefault();
-
- setSubmitLoader(true);
-
- const redirectionToast = toast.loading("Applying...");
-
- const response = await updateAccount({
- ...account,
- username: inputedUsername,
- });
-
- if (response.ok) {
- toast.success("Username Applied!");
-
- update({
- id: data?.user.id,
- });
- } else toast.error(response.data as string);
- toast.dismiss(redirectionToast);
- setSubmitLoader(false);
- }
-
- return (
-
-
-
- );
-}