MCPcopy Create free account
hub / github.com/SeaQL/sea-orm / login

Function login

examples/react_admin/backend/src/controllers/auth.rs:130–146  ·  view source on GitHub ↗
(State(ctx): State<AppContext>, Json(params): Json<LoginParams>)

Source from the content-addressed store, hash-verified

128/// Creates a user login and returns a token
129#[debug_handler]
130async fn login(State(ctx): State<AppContext>, Json(params): Json<LoginParams>) -> Result<Response> {
131 let user = users::Model::find_by_email(&ctx.db, &params.email).await?;
132
133 let valid = user.verify_password(&params.password);
134
135 if !valid {
136 return unauthorized("unauthorized!");
137 }
138
139 let jwt_secret = ctx.config.get_jwt_config()?;
140
141 let token = user
142 .generate_jwt(&jwt_secret.secret, &jwt_secret.expiration)
143 .or_else(|_| unauthorized("unauthorized!"))?;
144
145 format::json(LoginResponse::new(&user, &token))
146}
147
148pub fn routes() -> Routes {
149 Routes::new()

Callers

nothing calls this directly

Calls 4

jsonFunction · 0.85
newFunction · 0.50
verify_passwordMethod · 0.45
generate_jwtMethod · 0.45

Tested by

no test coverage detected