My first web application built in Rust (and Vue.js)

Hi, I am thebluetropics. I begin learning the Rust Programming Language about three weeks ago. After going through a lot of fighting with the borrow checker, I finally made my first ever web app in Rust and Vue.js!

And I like to share the project with everyone here:

I really appreciate for any critics/suggestion that will improve the project!

A few quick observations:

  • Don't use a plain String to represent the password and its hash. You should mask these values so that they don't appear in your logs by accident.
  • Rust is an expression-based language, which among other things means that the last expression within a function body becomes its returned value. This means that you shouldn't use the bail macro when it's the last expression.
  • You have an AuthError enum, but doesn't seem to be used anywhere. On top of that, you have another ApiErrorResponse struct which is only used in the main function. You should unify your error handling (enums and API responses).
2 Likes

Hi, @moy2010!

Thank you for the suggestions, I really appreciate that. And here's my clarification:

You have an AuthError enum, but doesn't seem to be used anywhere.

I use AuthError enum, basically whenever the user is: (1) trying to create an account with existing username, (2) login with the wrong password, (3) or the JWT token is expired.

I am pretty sure I use it inside the server.rs.

You should unify your error handling (enums and API responses).

Sorry, but I don't quite understand what does this means. Can you please give me a brief example?

As for the other two suggestion you gave me, I don't see any reason to not follow it.

For the hash, I will use argon2::PasswordHash instead of using the plain String. And then converting it to String later when sending the HTTP response. I am not sure if this the correct solution. Tell me if I missed something...

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.