Giter Club home page Giter Club logo

wpcodevo / rust-axum-jwt-auth Goto Github PK

View Code? Open in Web Editor NEW
96.0 1.0 10.0 23 KB

Are you interested in building a secure authentication system for your Rust web application? Look no further than the Axum framework and JSON Web Tokens (JWTs)! Axum is a fast and scalable Rust web framework that provides a reliable and efficient platform for developing microservices and APIs.

Home Page: https://codevoweb.com/jwt-authentication-in-rust-using-axum-framework/

Makefile 4.55% Rust 95.45%
axum axum-framework axum-server docker docker-compose jwt jwt-auth jwt-authentication postgresql sqlx

rust-axum-jwt-auth's Introduction

JWT Authentication in Rust using Axum Framework

Are you interested in building a secure authentication system for your Rust web application? Look no further than the Axum framework and JSON Web Tokens (JWTs)! Axum is a fast and scalable Rust web framework that provides a reliable and efficient platform for developing microservices and APIs.

JWT Authentication in Rust using Axum Framework

Topics Covered

  • Set Up and Test the Rust Axum JWT Authentication Project
  • Setup the Rust Axum Project
  • Setup the PostgreSQL and pgAdmin Servers
  • Load the Environment Variables
  • Create and Push the Database Migrations
  • Connect the App to the PostgreSQL Database
  • Define the SQLX Database Model
  • Define the Response Structures
  • Create the Axum JWT Authentication Middleware
  • Implement the JWT Authentication in Axum
    • Axum User Registration Handler
    • Axum User Login Handler
    • Axum User Logout Handler
    • Axum Handler to Fetch Logged-in User
    • The Complete Code for the Axum Handlers
  • Create the API Routes
  • Register the API Router and Setup CORS
  • Conclusion

Read the entire article here: https://codevoweb.com/jwt-authentication-in-rust-using-axum-framework/

rust-axum-jwt-auth's People

Contributors

wpcodevo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

rust-axum-jwt-auth's Issues

Using Trait Into/TryFrom for changing struct between User and FilterUser

https://doc.rust-lang.org/stable/rust-by-example/conversion/try_from_try_into.html

Do not implement a function like this:

fn filter_user_record(user: &User) -> FilteredUser {
FilteredUser {
id: user.id.to_string(),
email: user.email.to_owned(),
name: user.name.to_owned(),
photo: user.photo.to_owned(),
role: user.role.to_owned(),
verified: user.verified,
createdAt: user.created_at.unwrap(),
updatedAt: user.updated_at.unwrap(),
}
}

I can't compile the code, it prompts a compilation error, could you help me?

When compiling the program, it prompts:
error[E0277]: the trait bound fn(axum::extract::State<Arc<AppState>>, axum::Json<RegisterUserSchema>) -> impl std::future::Future<Output = Result<impl IntoResponse, (axum::http::StatusCode, axum::Json<JsonValue>)>> {register_user_handler}: Handler<_, _, _> is not satisfied
--> src/route.rs:21:43
|
21 | .route("/api/auth/register", post(register_user_handler))
| ---- ^^^^^^^^^^^^^^^^^^^^^ the trait Handler<_, _, _> is not implemented for fn item fn(axum::extract::State<Arc<AppState>>, axum::Json<RegisterUserSchema>) -> impl std::future::Future<Output = Result<impl IntoResponse, (axum::http::StatusCode, axum::Json<JsonValue>)>> {register_user_handler}
| |
| required by a bound introduced by this call
|
= help: the following other types implement trait Handler<T, S, B>:
<Or<L, R, Lt, Rt, S, B> as Handler<(M, Lt, Rt), S, B>>
<IntoHandler<H, T, S, B> as Handler<T, S, B>>
<Layered<L, H, T, S, B, B2> as Handler<T, S, B2>>
<MethodRouter<S, B> as Handler<(), S, B>>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.