Skip to content

Commit 3de193b

Browse files
authored
Merge pull request #86 from campos02/main
2 parents 644caa2 + 43f950f commit 3de193b

File tree

4 files changed

+39
-40
lines changed

4 files changed

+39
-40
lines changed

src/api/mod.rs

+35-32
Original file line numberDiff line numberDiff line change
@@ -49,41 +49,11 @@ pub async fn start_api(
4949
));
5050
}
5151

52-
let routes = Route::new()
53-
.nest("/auth", auth::setup_routes())
54-
.nest(
55-
"/users",
56-
users::setup_routes()
57-
.with(AuthenticationMiddleware)
58-
.with(CurrentUserMiddleware),
59-
)
60-
.nest(
61-
"/guilds",
62-
guilds::setup_routes()
63-
.with(AuthenticationMiddleware)
64-
.with(CurrentUserMiddleware),
65-
)
66-
.nest(
67-
"/channels",
68-
channels::setup_routes()
69-
.with(AuthenticationMiddleware)
70-
.with(CurrentUserMiddleware),
71-
)
72-
.nest(
73-
"/invites",
74-
routes::invites::setup_routes()
75-
.with(AuthenticationMiddleware)
76-
.with(CurrentUserMiddleware),
77-
)
78-
.nest("/policies", routes::policies::setup_routes())
79-
.nest("/-", routes::health::setup_routes())
80-
.at("/version", routes::version::setup_routes())
81-
.at("/ping", routes::ping::setup_routes());
82-
8352
let v9_api = Route::new()
8453
.at("/ping", routes::ping::setup_routes())
8554
.at("/version", routes::version::setup_routes())
86-
.nest("/api/v9", routes)
55+
.nest("/api", setup_api_routes())
56+
.nest("/api/v9", setup_api_routes())
8757
.data(db)
8858
.data(config)
8959
.data(connected_users)
@@ -118,6 +88,39 @@ pub async fn start_api(
11888
Ok(())
11989
}
12090

91+
fn setup_api_routes() -> Route {
92+
Route::new()
93+
.nest("/auth", auth::setup_routes())
94+
.nest(
95+
"/users",
96+
users::setup_routes()
97+
.with(AuthenticationMiddleware)
98+
.with(CurrentUserMiddleware),
99+
)
100+
.nest(
101+
"/guilds",
102+
guilds::setup_routes()
103+
.with(AuthenticationMiddleware)
104+
.with(CurrentUserMiddleware),
105+
)
106+
.nest(
107+
"/channels",
108+
channels::setup_routes()
109+
.with(AuthenticationMiddleware)
110+
.with(CurrentUserMiddleware),
111+
)
112+
.nest(
113+
"/invites",
114+
routes::invites::setup_routes()
115+
.with(AuthenticationMiddleware)
116+
.with(CurrentUserMiddleware),
117+
)
118+
.nest("/policies", routes::policies::setup_routes())
119+
.nest("/-", routes::health::setup_routes())
120+
.at("/version", routes::version::setup_routes())
121+
.at("/ping", routes::ping::setup_routes())
122+
}
123+
121124
async fn custom_error(err: poem::Error) -> impl IntoResponse {
122125
Json(json! ({
123126
"success": false,

src/api/routes/auth/login.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,11 @@ pub async fn login(
100100
&cfg.security.jwt_secret,
101101
);
102102

103-
//let user_settings = user.get_settings()
104-
105103
Ok(Response::builder()
106104
.body(
107105
json!({
108106
"token": token,
109-
"settings": {}
107+
"settings": user.settings
110108
})
111109
.to_string(),
112110
)

src/api/routes/policies/instance/domain.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@ pub async fn domain(
3131
} else if let Some(endpoint) = &cfg.gateway.endpoint_public {
3232
endpoint.to_owned()
3333
} else {
34-
"http://localhost:3003".to_string()
34+
"ws://localhost:3003".to_string()
3535
};
3636

3737
let api = if let Ok(endpoint) = std::env::var("API") {
3838
endpoint
3939
} else if let Some(endpoint) = &cfg.api.endpoint_public {
4040
endpoint.to_owned()
4141
} else {
42-
"http://localhost:3001".to_string()
42+
"http://localhost:3001/api".to_string()
4343
};
4444

4545
Ok(Json(json!({

src/util/token.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ pub async fn check_token(db: &PgPool, token: &str, jwt_secret: &str) -> Result<C
2323
.unwrap()
2424
.ok_or(Error::User(UserError::InvalidUser))?;
2525

26-
// TODO(bitfl0wer): I changed the direction of the comparison here (from < to >) to fix a bug. I don't know if this is correct,
27-
// nor have I looked at this code at all to see if it's correct.
28-
if chrono::DateTime::from_timestamp(token.claims.iat, 0).unwrap() > user.data.valid_tokens_since
26+
if chrono::DateTime::from_timestamp(token.claims.iat, 0).unwrap() < user.data.valid_tokens_since
2927
{
3028
return Err(Error::User(UserError::InvalidToken));
3129
}

0 commit comments

Comments
 (0)