Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

Creating a login page is now a very trivial task since we have all functionality set up for our application. It will be looking similar to the register page.

Login page

Login store

Create a new store src/stores/login.js with the following content:...

The Full Lesson is Only for Premium Members

Want to access all of our courses? (29 h 14 min)

You also get:

54 courses
Premium tutorials
Access to repositories
Private Discord
Get Premium for $129/year or $29/month

Already a member? Login here

Comments & Discussion

CM
Chris McGee ✓ Link copied!

Did I miss some steps? After registering a user, I'm still on the registration page, just with the password fields blanked out and the "Login" and "Register" links still in the corner.

After an artisan migrate:fresh, Now registering takes me to the Login page, but it looks like I'm already logged in, because the link in the corner changes to "Logout". And if I try logging in anyway, it just keeps me on the Login page and blanks out the password field. Clicking that "Logout" link takes me to the Registration page, so I guess that's working?

I feel like I've got my redirects incorrect, unless they will be fixed in an upcoming lesson.

DL
David Lun ✓ Link copied!

it looks like you've missed something. everything should be working properly by this point.

CM
Chris McGee ✓ Link copied!

As it turns out, I typo'd.

In the /src/stores/auth.js file, I had const accessToken = useStorage("access-token", ""); instead of const accessToken = useStorage("access_token", "");

Egg on my face.

T
twatwak ✓ Link copied!

Current method of authenticating user has flaws. Like user can set access-token from browser manually and get access to the page. How can I avoid this ?

DL
David Lun ✓ Link copied!

What do you mean? User can also give correct password and get access to the page. Cookies also can be set by user. Could you explain what are you trying to achieve?

MN
Matthaus Nawan ✓ Link copied!

verifiy if token is valid before Enter the page!

A
augusto-dmh ✓ Link copied!

Matthaus, if the user even enters on a page having an invalid access token, ANY operation that needs that token if performed will make the access token be removed from localStorage.

This happens because of the interceptor we've added to bootstrap.js file, which runs whenever we receive either success or failure from an axios call.

In case of failure with 401 error (that is thrown whenever we try to reach a route that needs the access token and we either don't have it or have one that is invalid, at least second to the api) the destroyTokenAndRedirectTo from auth store gets called.

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.