johnny  the fifth
johnny the fifth
TTCTheo's Typesafe Cult
Created by johnny the fifth on 11/4/2024 in #questions
is it ok to have two rows for friendship between two users in my friends table?
i am working on adding friends feature in my app let's say User A sends a friend request to User B then User B sends to user A , a friend request is it ok to have two rows one when User A send user User B a friend request and vice versa to indicate that these users are friends or is there a better way to do the friendship in my database .
4 replies
TTCTheo's Typesafe Cult
Created by johnny the fifth on 10/19/2024 in #questions
next js middleware infinite redirect
I have three pages in my app register , login , home if user is not logged he gets redirected to login page , the home page is accessed only if the user is authenticated which is determined if there is a cookie in the browser I wanna implement protected routes via next js middleware scenario : I am having a issue when I login I am redirected to the home page if I go i should be redirected to the home page the previous page is the login page when I do that problem: i get a too many redirects error for a moment then I am redirected to home page as expected I inspected the network tab there is a pattern that goes like this before i am finally redirected to the home page /login page requested (307 temporary redirect) , /home page requested(307 temporary redirect) repeated several times , I also wanna mention that this happens when i am at the login page and try to go to forward and backward pages and get redirected to login since i am not logged in and then login get redirected to home page and try to go back here is the code
import { NextRequest, NextResponse } from 'next/server';
export function middleware(request: NextRequest, response: NextResponse) {
const isUserLogged = request.cookies.get('chat_accessToken');
const pathname = request.nextUrl.pathname;
console.log('pathname', pathname);
const authPaths = ['/login', '/register'];
if (
(isUserLogged && pathname == '/') ||
(isUserLogged && authPaths.includes(pathname)) ||
(isUserLogged && pathname !== '/home/chats')
) {
return NextResponse.redirect(new URL('/home/chats', request.url));
}
else if (!authPaths.includes(pathname) && !isUserLogged) {
return NextResponse.redirect(new URL('/login', request.url));
} else if (!isUserLogged && authPaths.includes(pathname)) {
return NextResponse.next();
}
return NextResponse.next();
}
export const config = {
matcher: [
'/((?!api|_next/static|_next/image|favicon.ico).*)',
],
};
import { NextRequest, NextResponse } from 'next/server';
export function middleware(request: NextRequest, response: NextResponse) {
const isUserLogged = request.cookies.get('chat_accessToken');
const pathname = request.nextUrl.pathname;
console.log('pathname', pathname);
const authPaths = ['/login', '/register'];
if (
(isUserLogged && pathname == '/') ||
(isUserLogged && authPaths.includes(pathname)) ||
(isUserLogged && pathname !== '/home/chats')
) {
return NextResponse.redirect(new URL('/home/chats', request.url));
}
else if (!authPaths.includes(pathname) && !isUserLogged) {
return NextResponse.redirect(new URL('/login', request.url));
} else if (!isUserLogged && authPaths.includes(pathname)) {
return NextResponse.next();
}
return NextResponse.next();
}
export const config = {
matcher: [
'/((?!api|_next/static|_next/image|favicon.ico).*)',
],
};
2 replies
TTCTheo's Typesafe Cult
Created by johnny the fifth on 9/15/2024 in #questions
platforms to deploy node js backend with free plans
hey guys I am developing a node js backend with mysql I am looking for deployment platforms with free plans this is a portfolio project i don't want to spend any money on it
2 replies
TTCTheo's Typesafe Cult
Created by johnny the fifth on 9/14/2024 in #questions
mysql free deployment platforms
I am working on a personal chat-app project with no intentions for it to be a production app (maybe in the far future not so sure ) I am gonna use mysql with prisma , node js , socket io for the backend. I have researched for platforms to deploy my mysql database however pretty much every platform i came across didn't have a free plan , I have no intention to spend money on this project it's only for my portfolio here are the platforms i have seen : plantscale , render , railway , awardspace and some other platforms that i don't remember
10 replies
TTCTheo's Typesafe Cult
Created by johnny the fifth on 8/21/2024 in #questions
how to fix images adjusting after loading
No description
7 replies
TTCTheo's Typesafe Cult
Created by johnny the fifth on 8/11/2024 in #questions
does the interviewer (technical interviewer) or dev responsible for hiring review your projects code
I am refactoring an old project it's an ecommerce project i didn't have the option to view the product in a seprate page so i wanted to add that option , I have my products stored in an Array in firebase now that i understand firebase more i learned that i can't use it's querying capabilities to filter my results instead of having to loop over the whole Array to get the item i want it's a total of 226 items i know that if i add more products it will effect performance later there is two choices either i restructure my database again which will be a pain the ass for me or i can just work with the current structure the question is given that option 1 this is not the best approach i am worried that if an employer or developer sees that implementation that would discourage them from hiring me plus does the developer who hires you even bother to look at your code
29 replies
TTCTheo's Typesafe Cult
Created by johnny the fifth on 8/7/2024 in #questions
which approach is better in regards to better code
i have a signUp function that need the useDispatch redux hook I have defined this function in a useRegister() hook which is then used in register page the signUp function is called internally in my useRegister hook, the question is since i need my useDispatch hook , along with other functions (setLoadingState ,setModalToggle) these funtions set the state of my App do i keep the sign up function defined in useRegister() hook or do i define it in another file functions.ts file and pass the useDispatch , setLoading ,setModalToggle which approach is better and cleaner
2 replies
TTCTheo's Typesafe Cult
Created by johnny the fifth on 8/3/2024 in #questions
redirection not working from root path "/" (react-router v6)
I am using react-router version ^6.25.1 , I want the user to be redirected to the home page /home if he logged in before i am using firebase-auth I check if the user is logged in via onAuthStateChanged observer provided by firebase if there is a user logged the promise is resolved if not it gets reject i am using a loader function to do this check if i call the loader function in my root "/" element the page keeps loading and I am not redirected however if i do that in other pages such as "/LoginPage" i am able to redirect to the home page /home
3 replies
TTCTheo's Typesafe Cult
Created by johnny the fifth on 7/19/2024 in #questions
which method is better for authentication
i am building an app using mysql , next js , nodejs-express , socket io i am currently in the phase of authentication and registering users in my database with all of their info (email,username,password etc..) the question is do i just encrypt users password in my database when they register into my App or do i use an authentication solution , the registeration data will be sent to the express server where the insertion process will take place in my database when the user sign in i am planning to use jwt with cookies probably or do i use an authentication solution this is my first time building a fullstack app .
6 replies
TTCTheo's Typesafe Cult
Created by johnny the fifth on 7/15/2024 in #questions
do i create a sepreate notification and user_notifications table in my database
I am working on a chat app using prisma and mysql here are some details my app it will include rooms where users can join like servers in discord you can add friends to the room , create your own room kinda like discord, i am currently in the phase of structuring my database , i am currently structuring the notifications , i am a bit struggling on how to go about my notifications structure in the database my chat app will have friend request notifications and other types of notifications i thought i can just create a table for notifications now what if there is a 100 users let's say 50 of them send friend requests to the other 50 i would have like 50 records or something in the notifications table , what if the room admin (owner) sends a friend request to all members of the room again we will have like x amount of records for each notification the admin sends to the users in the table i thought the notifcations should be sent to the room_id and the users that joined the room with that room id should have that notification but there is problem we still need to have records with the notification for these users do i have all these notifications records in one table or do I create a table for all notifications in the App and a sepreate one for user_notifications that will have the notifications for each users ?
2 replies
TTCTheo's Typesafe Cult
Created by johnny the fifth on 6/30/2024 in #questions
Do i use server components , actions over express JS for my App
i am building a chat app that will use socket io , mySQL database , next js , jwt for authentication as well , i was planning to use express js for the backend for my websocket server logic i was following the next js 14 tutorial they used server actions to submit form data for the new users and the rest of the App to their hosted postgre sql database is there any disadvantages for using server action and components for handling database logic over express js endpoints before i read the docs i was gonna handle both jwt , database logic with express js in the backend i saw this new react feature and i am a bit confused on which way to go and is it gonna work if i take the server actions components path ?
14 replies
TTCTheo's Typesafe Cult
Created by johnny the fifth on 4/11/2024 in #questions
You are using Node.js 16.17.0. For Next.js, Node.js version >= v18.17.0 is required.
i have installed the latest version of next js via npx create-next-app@latest i have node js version 20.12.1 i checked with node -v , i have also checked the path variable it does point to my node js folder ,i reinstalled node js , but unfourtuntely that all didn't work i am using npm run devto run the project
2 replies
TTCTheo's Typesafe Cult
Created by johnny the fifth on 10/31/2023 in #questions
how do i use typescript with node inspect
i wanted to be able to console log my express app in the browser instead of seeing logs in the terminal .
2 replies
TTCTheo's Typesafe Cult
Created by johnny the fifth on 10/16/2023 in #questions
Refused to apply style from 'http://localhost:8080/dist/output.css' because its MIME type
No description
2 replies
TTCTheo's Typesafe Cult
Created by johnny the fifth on 10/7/2023 in #questions
how do developers learn from the docs ?
i have been in the web dev field for about 2 + years when i want to learn a technology node js for example i would get a course or read a book every time i try to learn from the docs i would find it almost impossible to implement anything i learned in a real world app or even build one ,the docs doesn't explain how to use that knowledge in a real world app or even give examples on how to do so i wonder how do other devs who make the courses or the books know how to build apps and do stuff just learning from docs ?
10 replies
TTCTheo's Typesafe Cult
Created by johnny the fifth on 9/26/2022 in #questions
can i remove a background from an image using Js
25 replies