Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: admin role support #46

Merged
merged 2 commits into from
Jan 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion link-for-later/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ chrono = { version = "0.4.31", default-features = false, features=["clock", "ser
futures = "0.3.29"
http-body-util = "0.1.0"
jsonwebtoken = "9.2.0"
link-for-later-types = { git = "https://github.com/kentSarmiento/link-for-later-types", tag = "v0.1.0" }
link-for-later-types = { git = "https://github.com/kentSarmiento/link-for-later-types", branch = "develop" }
mongodb = "2.8.0"
reqwest = { version = "0.11.23", default-features = false, features = ["json", "rustls-tls"] }
serde = { version = "1.0.193", features = ["derive"] }
Expand Down
8 changes: 7 additions & 1 deletion link-for-later/src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ use serde::{Deserialize, Serialize};
#[derive(Debug, Default, Serialize, Deserialize)]
pub struct Claims {
sub: String, // email
admin: bool, // admin role
iat: usize, // creation time
exp: usize, // expiration time
}

impl Claims {
pub fn new(sub: &str, iat: usize, exp: usize) -> Self {
pub fn new(sub: &str, admin: bool, iat: usize, exp: usize) -> Self {
Self {
sub: sub.to_owned(),
admin,
iat,
exp,
}
Expand All @@ -19,6 +21,10 @@ impl Claims {
pub fn id(&self) -> &str {
&self.sub
}

pub const fn is_admin(&self) -> bool {
self.admin
}
}

#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
Expand Down
Loading
Loading