29
Technical Aspects of Bytes
⚠️⚠️ Project is no longer maintained or hosted. The code is available on Github
If you are unaware of Bytes then check out this blog that I wrote:
Bytes - A Platform to share bite-sized learnings!
In this blog, I'll talk about the decision to choosing the tech stack, the database modeling of Bytes
export type UserSchema = {
uid: string;
email: string;
name: string;
username: string;
verified: boolean;
__createdtime__?: string;
__updatedtime__?: string;
};
export type PostSchema = {
pid: string;
images: Array<string>;
slug: string;
title: string;
uid: string;
reactions: number;
__createdtime__?: string;
__updatedtime__?: string;
};
export type TagType = {
tid: string;
name: string;
color: string;
image?: string;
slug?: string;
__createdtime__?: string;
__updatedtime__?: string;
};
export type Post_Tag_Type = {
pid: string;
ptid: string;
tid: string;
__createdtime__?: string;
__updatedtime__?: string;
};
uid
uid
-- Gets all the Posts of a User
SELECT p.*,u.name,u.username FROM bytes.post AS p INNER JOIN bytes.user AS u ON u.uid=p.uid WHERE u.username='${username}'
Post_Tag
that would contain a
post id as pid
and tag id as tid
-- Gets all Tags for a Post
SELECT t.* FROM bytes.post_tag AS pt INNER JOIN bytes.tag AS t ON pt.tid=t.tid WHERE pt.pid='${post.pid}'
-- Get all Posts of a Tag
SELECT p.*,u.name,u.username FROM bytes.post_tag AS pt INNER JOIN bytes.post AS p ON pt.pid=p.pid INNER JOIN bytes.user AS u ON p.uid = u.uid WHERE pt.tid='${tag.tid}'
- /
- /upload
- /login
- /profile/:id/
- /byte/:id/
- /tag/:id/
Out of this routes, the
/upload
route is protected, It can be only accessed if the user is logged in.// useRequireLogin.tsx
const router = useRouter();
const { user, setUser } = useContext(UserContext);
const [loading, setLoading] = useState(false);
useEffect(() => {
setLoading(true);
firebase.auth().onAuthStateChanged(async (user) => {
if (user) {
const authUser = await getAuthUserFromHarper(user.uid);
setUser({ ...authUser, isLoggedIn: true });
setLoading(false);
router.push(to);
} else {
setUser({});
setLoading(false);
router.push("/login");
}
});
}, []);
return { user, loading };
// ------------------------
// Using in the Upload Page
// /pages/upload.tsx
// ------------------------
const { user, loading } = useRequireLogin({ to: "/upload" });
if (loading || !user.isLoggedIn) return null;
Hope you liked this blog and learned something from it.
There are still some improvements and features that I am adding to Bytes.
There are still some improvements and features that I am adding to Bytes.
You can follow me on my Twitter - @Shubham_Verma18
29