Skip to content

⚡️⚡️⚡️ Self-hosted collaborative bookmark manager to collect, read, annotate, and fully preserve what matters, all in one place.

bug fixes

daniel31x13accbd4cbfa8c
diff --git a/components/InstallApp.tsx b/components/InstallApp.tsx
index f191f006..50071da6 100644
--- a/components/InstallApp.tsx
+++ b/components/InstallApp.tsx
@@ -8,7 +8,7 @@ const InstallApp = (props: Props) => {
const [isOpen, setIsOpen] = useState(true);
return isOpen && !isPWA() ? (
- <div className="fixed left-0 right-0 bottom-10 w-full p-5">
+ <div className="fixed left-0 right-0 bottom-10 w-full">
<div className="mx-auto w-fit p-2 flex justify-between gap-2 items-center border border-neutral-content rounded-xl bg-base-300 backdrop-blur-md bg-opacity-80 max-w-md">
<svg
xmlns="http://www.w3.org/2000/svg"
diff --git a/pages/api/v1/auth/[...nextauth].ts b/pages/api/v1/auth/[...nextauth].ts
index 7b6315f6..51cbe2af 100644
--- a/pages/api/v1/auth/[...nextauth].ts
+++ b/pages/api/v1/auth/[...nextauth].ts
@@ -1186,10 +1186,42 @@ export default async function auth(req: NextApiRequest, res: NextApiResponse) {
providerAccountId: account?.providerAccountId,
},
});
+
if (!existingUser && newSsoUsersDisabled) {
return false;
}
+
+ // If user is already registered, link the provider
+ if (user.email && account) {
+ const findUser = await prisma.user.findFirst({
+ where: {
+ email: user.email,
+ },
+ include: {
+ accounts: true,
+ },
+ });
+
+ if (findUser && findUser.accounts.length === 0) {
+ await prisma.account.create({
+ data: {
+ userId: findUser.id,
+ type: account.type,
+ provider: account.provider,
+ providerAccountId: account.providerAccountId,
+ id_token: account.id_token,
+ access_token: account.access_token,
+ refresh_token: account.refresh_token,
+ expires_at: account.expires_at,
+ token_type: account.token_type,
+ scope: account.scope,
+ session_state: account.session_state,
+ },
+ });
+ }
+ }
}
+
return true;
},
async jwt({ token, trigger, user }) {
@@ -1198,13 +1230,28 @@ export default async function auth(req: NextApiRequest, res: NextApiResponse) {
token.id = user?.id as number;
if (trigger === "signUp") {
- const checkIfUserExists = await prisma.user.findUnique({
+ const userExists = await prisma.user.findUnique({
where: {
id: token.id,
},
+ include: {
+ accounts: true,
+ },
});
- if (checkIfUserExists && !checkIfUserExists.username) {
+ // Verify SSO user email
+ if (userExists && userExists.accounts.length > 0) {
+ await prisma.user.update({
+ where: {
+ id: userExists.id,
+ },
+ data: {
+ emailVerified: new Date(),
+ },
+ });
+ }
+
+ if (userExists && !userExists.username) {
const autoGeneratedUsername =
"user" + Math.round(Math.random() * 1000000000);
@@ -1217,6 +1264,22 @@ export default async function auth(req: NextApiRequest, res: NextApiResponse) {
},
});
}
+ } else if (trigger === "signIn") {
+ const user = await prisma.user.findUnique({
+ where: {
+ id: token.id,
+ },
+ });
+
+ if (user && !user.username) {
+ const autoGeneratedUsername =
+ "user" + Math.round(Math.random() * 1000000000);
+
+ await prisma.user.update({
+ where: { id: user.id },
+ data: { username: autoGeneratedUsername },
+ });
+ }
}
return token;
@@ -1224,6 +1287,8 @@ export default async function auth(req: NextApiRequest, res: NextApiResponse) {
async session({ session, token }) {
session.user.id = token.id;
+ console.log("session", session);
+
if (STRIPE_SECRET_KEY) {
const user = await prisma.user.findUnique({
where: {
@@ -1235,6 +1300,7 @@ export default async function auth(req: NextApiRequest, res: NextApiResponse) {
});
if (user) {
+ //
const subscribedUser = await verifySubscription(user);
}
}