feat: add auth

This commit is contained in:
2025-12-25 22:32:04 +01:00
parent 71d915ff0f
commit e7fe00c48d
17 changed files with 1654 additions and 35 deletions

View File

@@ -1,10 +1,16 @@
use std::{env, error::Error};
use std::env;
use actix_files::Files;
use actix_web::{App, HttpResponse, HttpServer, Responder, get, web};
use scp_core::apis::configuration::Configuration;
use scp_core::apis::default_api;
mod auth;
mod db;
mod helper;
mod jobs;
mod models;
#[get("/api/hello")]
async fn hello() -> impl Responder {
HttpResponse::Ok().json(serde_json::json!({ "message": "hello" }))
@@ -18,7 +24,6 @@ async fn spa_fallback() -> actix_web::Result<actix_files::NamedFile> {
async fn ping_netcup() -> impl Responder {
let config = Configuration::default();
let res = default_api::api_ping_get(&config).await;
dbg!(&res);
res.is_ok().to_string()
}
@@ -30,10 +35,18 @@ async fn main() -> std::io::Result<()> {
.parse::<u16>()
.unwrap();
HttpServer::new(|| {
db::migrate().await.expect("Error migrating!");
let rt_handle = tokio::runtime::Handle::current();
let scheduler = jobs::init_scheduler(rt_handle.clone());
let res = HttpServer::new(|| {
App::new()
.service(hello)
.service(ping_netcup)
.service(auth::is_scp_logged_in)
.service(auth::start_flow)
.service(auth::get_user)
.service(
Files::new("/", "./frontend/dist")
.index_file("index.html")
@@ -43,5 +56,8 @@ async fn main() -> std::io::Result<()> {
})
.bind(("127.0.0.1", port))?
.run()
.await
.await;
scheduler.shutdown();
res
}