Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Medea
Medea

Posted on

     

Login and Signup with Next.js

I recently started learning Next.js and I wanted to improve my Next.js skills, so I decided to make a simple Login and Signup Website with Next.js and MongoDB.

The website has 4 pages and 3 API routes:

  • /: where the user can see if they have logged in or not, and view all the other pages they can access
  • /login: a page where the user can login
  • /signup: the page where the user can signup for an account
  • /profile: where the user can check their account creation date
  • /api/signup: the API route where a user's account is created
  • /api/login: the API route where the password entered is checked
  • /api/logout: the API route where the username cookie is deleted

I have used cookies to check if the user has logged in.
The cookies are set and deleted in the/api routes but read usinggetServerSideProps.

The full source code can be viewed in this GitHub repo:


Can you check out the code and give me ways I can improve?

Top comments(12)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss
CollapseExpand
 
mahesh4net profile image
Techno is live
a developer :)
  • Joined

I have tried it, but itsauthentication is not secure enough, i was able to bypass login at all.
you are just setting a cookie named username which can have a user's registered name. i just added the username cookie and my username manually and it logged me in. WITHOUT ANY PASSWORD !

CollapseExpand
 
vulcanwm profile image
Medea
A 16 year old full-stack developer who codes for fun and loves building projects related to music
  • Location
    England
  • Pronouns
    she/her
  • Joined

yes i know
i made this post ages ago and have never actually used this method myself
my recommendation is to use an auth client like next auth

CollapseExpand
 
stcollier profile image
Samuel Collier
Student who enjoys the liberal arts along with web && game development
  • Joined

Hey, this is really cool! It might be nice to add email verification so that people can't just spam accounts. Otherwise nice work :)

CollapseExpand
 
vulcanwm profile image
Medea
A 16 year old full-stack developer who codes for fun and loves building projects related to music
  • Location
    England
  • Pronouns
    she/her
  • Joined

that seems like a great idea, ill try it out! thanks :)

CollapseExpand
 
nicu420 profile image
Onța Nicolae
  • Joined

Image description

CollapseExpand
 
vulcanwm profile image
Medea
A 16 year old full-stack developer who codes for fun and loves building projects related to music
  • Location
    England
  • Pronouns
    she/her
  • Joined

that shows up sometimes…
I’ll try to find out how to fix it

CollapseExpand
 
orunto profile image
Orunto Eniola
Tech Bro in Transit
  • Pronouns
    He/They
  • Joined

In case you're still wondering what it is. It's an issue from the user's end and it cannot be fixed unless with a stronger password.

Thread Thread
 
vulcanwm profile image
Medea
A 16 year old full-stack developer who codes for fun and loves building projects related to music
  • Location
    England
  • Pronouns
    she/her
  • Joined

oh okay thats fine then, thanks!

CollapseExpand
 
sonicx180 profile image
sonicx180
Fullstack dev | Javascript Enthusiast
  • Joined

It's cool, but I'd recommend using next connect for API routes.

CollapseExpand
 
vulcanwm profile image
Medea
A 16 year old full-stack developer who codes for fun and loves building projects related to music
  • Location
    England
  • Pronouns
    she/her
  • Joined

oh ill try that out

CollapseExpand
 
srini2024 profile image
Srinivasan
  • Joined

Good Post, Password Strength Checker Validation feature would have been good too

CollapseExpand
 
vulcanwm profile image
Medea
A 16 year old full-stack developer who codes for fun and loves building projects related to music
  • Location
    England
  • Pronouns
    she/her
  • Joined

that's true

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

A 16 year old full-stack developer who codes for fun and loves building projects related to music
  • Location
    England
  • Pronouns
    she/her
  • Joined

More fromMedea

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp