⚡️⚡️⚡️ Self-hosted collaborative bookmark manager to collect, read, annotate, and fully preserve what matters, all in one place.
TypeScript bookmarkbookmark-managercollaborationnextjsreact-nativeread-it-laterself-hostedtypescript
bug fix + use id instead of username for lookup
Daniel35bece5f4940
diff --git a/components/Modal/User/index.tsx b/components/Modal/User/index.tsxindex 199d9bb7..eb9ee603 100644--- a/components/Modal/User/index.tsx+++ b/components/Modal/User/index.tsx@@ -24,6 +24,8 @@ export default function UserModal({}: Props) {const [user, setUser] = useState<AccountSettings>(activeUser);+ console.log(activeUser);+return (<div className={className}><Tab.Group defaultIndex={defaultIndex}>diff --git a/hooks/useInitialData.tsx b/hooks/useInitialData.tsxindex 5655de39..a25faddf 100644--- a/hooks/useInitialData.tsx+++ b/hooks/useInitialData.tsx@@ -17,7 +17,7 @@ export default function useInitialData() {setCollections();setTags();// setLinks();- setAccount(data.user.username as string);+ setAccount(data.user.id);}}, [status]);}diff --git a/lib/api/controllers/collections/postCollection.ts b/lib/api/controllers/collections/postCollection.tsindex 213266ac..8e4cc991 100644--- a/lib/api/controllers/collections/postCollection.ts+++ b/lib/api/controllers/collections/postCollection.ts@@ -42,7 +42,7 @@ export default async function postCollection(color: collection.color,members: {create: collection.members.map((e) => ({- user: { connect: { username: e.user.username.toLowerCase() } },+ user: { connect: { id: e.user.id } },canCreate: e.canCreate,canUpdate: e.canUpdate,canDelete: e.canDelete,diff --git a/lib/api/controllers/collections/updateCollection.ts b/lib/api/controllers/collections/updateCollection.tsindex ac3dc65d..7d2c65eb 100644--- a/lib/api/controllers/collections/updateCollection.ts+++ b/lib/api/controllers/collections/updateCollection.ts@@ -43,7 +43,7 @@ export default async function updateCollection(isPublic: collection.isPublic,members: {create: collection.members.map((e) => ({- user: { connect: { username: e.user.username.toLowerCase() } },+ user: { connect: { id: e.user.id } },canCreate: e.canCreate,canUpdate: e.canUpdate,canDelete: e.canDelete,diff --git a/lib/api/controllers/users/getUsers.ts b/lib/api/controllers/users/getUsers.tsindex b75ea7f4..381a7139 100644--- a/lib/api/controllers/users/getUsers.ts+++ b/lib/api/controllers/users/getUsers.ts@@ -29,16 +29,16 @@ export default async function getUser({return { response: "This profile is private.", status: 401 };}- const { password, ...unsensitiveInfo } = user;+ const { password, ...lessSensitiveInfo } = user;const data = isSelf? // If user is requesting its own data- unsensitiveInfo+ lessSensitiveInfo: {// If user is requesting someone elses data- id: unsensitiveInfo.id,- name: unsensitiveInfo.name,- username: unsensitiveInfo.username,+ id: lessSensitiveInfo.id,+ name: lessSensitiveInfo.name,+ username: lessSensitiveInfo.username,};return { response: data || null, status: 200 };diff --git a/lib/api/paymentCheckout.ts b/lib/api/paymentCheckout.tsindex 63dac04f..9c2893cc 100644--- a/lib/api/paymentCheckout.ts+++ b/lib/api/paymentCheckout.ts@@ -4,7 +4,6 @@ import checkSubscription from "./checkSubscription";export default async function paymentCheckout(stripeSecretKey: string,email: string,- action: "register" | "login",priceId: string) {const stripe = new Stripe(stripeSecretKey, {diff --git a/pages/api/auth/[...nextauth].ts b/pages/api/auth/[...nextauth].tsindex 6777e1d1..5da3fec5 100644--- a/pages/api/auth/[...nextauth].ts+++ b/pages/api/auth/[...nextauth].ts@@ -110,7 +110,6 @@ export const authOptions: AuthOptions = {PRICE_ID &&(trigger || subscriptionIsTimesUp || !token.isSubscriber)) {- console.log("EXECUTED!!!");const subscription = await checkSubscription(STRIPE_SECRET_KEY,token.email as string,diff --git a/pages/api/avatar/[id].ts b/pages/api/avatar/[id].tsindex 0287229e..d4478663 100644--- a/pages/api/avatar/[id].ts+++ b/pages/api/avatar/[id].ts@@ -8,10 +8,10 @@ export default async function Index(req: NextApiRequest, res: NextApiResponse) {const session = await getServerSession(req, res, authOptions);const userId = session?.user.id;- const userName = session?.user.username?.toLowerCase();+ const username = session?.user.username?.toLowerCase();const queryId = Number(req.query.id);- if (!userId || !userName)+ if (!userId || !username)return res.setHeader("Content-Type", "text/plain").status(401)@@ -37,7 +37,7 @@ export default async function Index(req: NextApiRequest, res: NextApiResponse) {if (targetUser?.isPrivate &&- !targetUser.whitelistedUsers.includes(userName)+ !targetUser.whitelistedUsers.includes(username)) {return res.setHeader("Content-Type", "text/plain")diff --git a/pages/api/payment/index.ts b/pages/api/payment/index.tsindex 66566b7a..cd37cafa 100644--- a/pages/api/payment/index.ts+++ b/pages/api/payment/index.ts@@ -8,7 +8,7 @@ export default async function users(req: NextApiRequest, res: NextApiResponse) {const PRICE_ID = process.env.PRICE_ID;const session = await getServerSession(req, res, authOptions);- if (!session?.user?.username)+ if (!session?.user?.id)return res.status(401).json({ response: "You must be logged in." });else if (!STRIPE_SECRET_KEY || !PRICE_ID) {return res.status(400).json({ response: "Payment is disabled." });@@ -18,7 +18,6 @@ export default async function users(req: NextApiRequest, res: NextApiResponse) {const users = await paymentCheckout(STRIPE_SECRET_KEY,session?.user.email,- "register",PRICE_ID);return res.status(users.status).json({ response: users.response });diff --git a/pages/api/routes/collections/index.ts b/pages/api/routes/collections/index.tsindex 25fec73a..321dcd49 100644--- a/pages/api/routes/collections/index.ts+++ b/pages/api/routes/collections/index.ts@@ -12,7 +12,7 @@ export default async function collections() {const session = await getServerSession(req, res, authOptions);- if (!session?.user?.username) {+ if (!session?.user?.id) {return res.status(401).json({ response: "You must be logged in." });} else if (session?.user?.isSubscriber === false)res.status(401).json({diff --git a/pages/api/routes/links/index.ts b/pages/api/routes/links/index.tsindex 4a226d49..76ca6293 100644--- a/pages/api/routes/links/index.ts+++ b/pages/api/routes/links/index.ts@@ -9,7 +9,7 @@ import updateLink from "@/lib/api/controllers/links/updateLink";export default async function links(req: NextApiRequest, res: NextApiResponse) {const session = await getServerSession(req, res, authOptions);- if (!session?.user?.username) {+ if (!session?.user?.id) {return res.status(401).json({ response: "You must be logged in." });} else if (session?.user?.isSubscriber === false)res.status(401).json({diff --git a/pages/api/routes/users/index.ts b/pages/api/routes/users/index.tsindex 6757baba..2a1ecc19 100644--- a/pages/api/routes/users/index.ts+++ b/pages/api/routes/users/index.ts@@ -7,7 +7,7 @@ import updateUser from "@/lib/api/controllers/users/updateUser";export default async function users(req: NextApiRequest, res: NextApiResponse) {const session = await getServerSession(req, res, authOptions);- if (!session?.user.username) {+ if (!session?.user.id) {return res.status(401).json({ response: "You must be logged in." });} else if (session?.user?.isSubscriber === false)res.status(401).json({@@ -17,7 +17,10 @@ export default async function users(req: NextApiRequest, res: NextApiResponse) {const lookupUsername = (req.query.username as string) || undefined;const lookupId = Number(req.query.id) || undefined;- const isSelf = session.user.username === lookupUsername ? true : false;+ const isSelf =+ session.user.username === lookupUsername || session.user.id === lookupId+ ? true+ : false;if (req.method === "GET") {const users = await getUsers({@@ -34,10 +37,3 @@ export default async function users(req: NextApiRequest, res: NextApiResponse) {return res.status(updated.status).json({ response: updated.response });}}--// {-// lookupUsername,-// lookupId,-// },-// isSelf,-// session.user.usernamediff --git a/store/account.ts b/store/account.tsindex 7df75783..ae088063 100644--- a/store/account.ts+++ b/store/account.ts@@ -8,14 +8,14 @@ type ResponseObject = {type AccountStore = {account: AccountSettings;- setAccount: (username: string) => void;+ setAccount: (id: number) => void;updateAccount: (user: AccountSettings) => Promise<ResponseObject>;};const useAccountStore = create<AccountStore>()((set) => ({account: {} as AccountSettings,- setAccount: async (username) => {- const response = await fetch(`/api/routes/users?username=${username}`);+ setAccount: async (id) => {+ const response = await fetch(`/api/routes/users?id=${id}`);const data = await response.json();