-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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(router): Add new JWT authentication variants and use them #2835
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
5482bbf
feat: add authentication and signup apis
ThisIsMani d84b953
feat: add jwt to dashboard routes
ThisIsMani a400424
refactor: rename user api types and fix clippy
ThisIsMani a2514aa
fix: typos
ThisIsMani 8fb9a75
Merge branch 'main' into signup
ThisIsMani 5d8d0fa
fix: toml dependencies
ThisIsMani f11212e
Merge branch 'main' into signup
ThisIsMani 4cff8ea
fix: hack
ThisIsMani fe12374
chore: run formatter
github-actions[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
use common_utils::events::{ApiEventMetric, ApiEventsType}; | ||
|
||
use crate::user::{ConnectAccountRequest, ConnectAccountResponse}; | ||
|
||
impl ApiEventMetric for ConnectAccountResponse { | ||
fn get_api_event_type(&self) -> Option<ApiEventsType> { | ||
Some(ApiEventsType::User { | ||
merchant_id: self.merchant_id.clone(), | ||
user_id: self.user_id.clone(), | ||
}) | ||
} | ||
} | ||
|
||
impl ApiEventMetric for ConnectAccountRequest {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
use common_utils::pii; | ||
use masking::Secret; | ||
|
||
#[derive(serde::Deserialize, Debug, Clone, serde::Serialize)] | ||
pub struct ConnectAccountRequest { | ||
pub email: pii::Email, | ||
pub password: Secret<String>, | ||
} | ||
|
||
#[derive(serde::Serialize, Debug, Clone)] | ||
pub struct ConnectAccountResponse { | ||
pub token: Secret<String>, | ||
pub merchant_id: String, | ||
pub name: Secret<String>, | ||
pub email: pii::Email, | ||
pub verification_days_left: Option<i64>, | ||
pub user_role: String, | ||
//this field is added for audit/debug reasons | ||
#[serde(skip_serializing)] | ||
pub user_id: String, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#[cfg(feature = "olap")] | ||
pub const MAX_NAME_LENGTH: usize = 70; | ||
#[cfg(feature = "olap")] | ||
pub const MAX_COMPANY_NAME_LENGTH: usize = 70; | ||
|
||
// USER ROLES | ||
#[cfg(any(feature = "olap", feature = "oltp"))] | ||
pub const ROLE_ID_ORGANIZATION_ADMIN: &str = "org_admin"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
use common_utils::errors::CustomResult; | ||
|
||
use crate::services::ApplicationResponse; | ||
|
||
pub type UserResult<T> = CustomResult<T, UserErrors>; | ||
pub type UserResponse<T> = CustomResult<ApplicationResponse<T>, UserErrors>; | ||
|
||
#[derive(Debug, thiserror::Error)] | ||
pub enum UserErrors { | ||
#[error("User InternalServerError")] | ||
InternalServerError, | ||
#[error("InvalidCredentials")] | ||
InvalidCredentials, | ||
#[error("UserExists")] | ||
UserExists, | ||
#[error("EmailParsingError")] | ||
EmailParsingError, | ||
#[error("NameParsingError")] | ||
NameParsingError, | ||
#[error("PasswordParsingError")] | ||
PasswordParsingError, | ||
#[error("CompanyNameParsingError")] | ||
CompanyNameParsingError, | ||
#[error("MerchantAccountCreationError: {0}")] | ||
MerchantAccountCreationError(String), | ||
#[error("InvalidEmailError")] | ||
InvalidEmailError, | ||
#[error("DuplicateOrganizationId")] | ||
DuplicateOrganizationId, | ||
} | ||
|
||
impl common_utils::errors::ErrorSwitch<api_models::errors::types::ApiErrorResponse> for UserErrors { | ||
fn switch(&self) -> api_models::errors::types::ApiErrorResponse { | ||
use api_models::errors::types::{ApiError, ApiErrorResponse as AER}; | ||
let sub_code = "UR"; | ||
match self { | ||
Self::InternalServerError => { | ||
AER::InternalServerError(ApiError::new("HE", 0, "Something Went Wrong", None)) | ||
} | ||
Self::InvalidCredentials => AER::Unauthorized(ApiError::new( | ||
sub_code, | ||
1, | ||
"Incorrect email or password", | ||
None, | ||
)), | ||
Self::UserExists => AER::BadRequest(ApiError::new( | ||
sub_code, | ||
3, | ||
"An account already exists with this email", | ||
None, | ||
)), | ||
Self::EmailParsingError => { | ||
AER::BadRequest(ApiError::new(sub_code, 7, "Invalid Email", None)) | ||
} | ||
Self::NameParsingError => { | ||
AER::BadRequest(ApiError::new(sub_code, 8, "Invalid Name", None)) | ||
} | ||
Self::PasswordParsingError => { | ||
AER::BadRequest(ApiError::new(sub_code, 9, "Invalid Password", None)) | ||
} | ||
Self::CompanyNameParsingError => { | ||
AER::BadRequest(ApiError::new(sub_code, 14, "Invalid Company Name", None)) | ||
} | ||
Self::MerchantAccountCreationError(error_message) => { | ||
AER::InternalServerError(ApiError::new(sub_code, 15, error_message, None)) | ||
} | ||
Self::InvalidEmailError => { | ||
AER::BadRequest(ApiError::new(sub_code, 16, "Invalid Email", None)) | ||
} | ||
Self::DuplicateOrganizationId => AER::InternalServerError(ApiError::new( | ||
sub_code, | ||
21, | ||
"An Organization with the id already exists", | ||
None, | ||
)), | ||
} | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it is going to be small enough (only a few lines), you might as well have the module defined inline instead of keeping it in a separate file.
Not a necessary change however.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once we add new APIs and new roles, this file is going to become big.