feat: Docker/gotrue (#43)
* feat: use gotrue from source instead of docker hub image * test: fix test due to gotrue upgrade * fix: update prod docker-compose * chore: cargo fmt --all
This commit is contained in:
parent
b3be09e264
commit
9fc2acbc35
|
|
@ -3,7 +3,7 @@ services:
|
||||||
postgres:
|
postgres:
|
||||||
build:
|
build:
|
||||||
context: .
|
context: .
|
||||||
dockerfile: docker/Dockerfile_postgres
|
dockerfile: docker/postgres.Dockerfile
|
||||||
environment:
|
environment:
|
||||||
- POSTGRES_USER=${POSTGRES_USER:-postgres}
|
- POSTGRES_USER=${POSTGRES_USER:-postgres}
|
||||||
- POSTGRES_DB=${POSTGRES_DB:-postgres}
|
- POSTGRES_DB=${POSTGRES_DB:-postgres}
|
||||||
|
|
@ -20,7 +20,9 @@ services:
|
||||||
- 6380:6379
|
- 6380:6379
|
||||||
|
|
||||||
gotrue:
|
gotrue:
|
||||||
image: supabase/gotrue
|
build:
|
||||||
|
context: .
|
||||||
|
dockerfile: docker/gotrue.Dockerfile
|
||||||
restart: on-failure
|
restart: on-failure
|
||||||
depends_on:
|
depends_on:
|
||||||
- postgres
|
- postgres
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ services:
|
||||||
postgres:
|
postgres:
|
||||||
build:
|
build:
|
||||||
context: .
|
context: .
|
||||||
dockerfile: docker/Dockerfile_postgres
|
dockerfile: docker/postgres.Dockerfile
|
||||||
environment:
|
environment:
|
||||||
- POSTGRES_USER=${POSTGRES_USER:-postgres}
|
- POSTGRES_USER=${POSTGRES_USER:-postgres}
|
||||||
- POSTGRES_DB=${POSTGRES_DB:-postgres}
|
- POSTGRES_DB=${POSTGRES_DB:-postgres}
|
||||||
|
|
@ -12,7 +12,7 @@ services:
|
||||||
ports:
|
ports:
|
||||||
- 5433:5432
|
- 5433:5432
|
||||||
volumes:
|
volumes:
|
||||||
- ./migrations/before/:/docker-entrypoint-initdb.d
|
- ./migrations/before:/docker-entrypoint-initdb.d
|
||||||
|
|
||||||
redis:
|
redis:
|
||||||
image: redis
|
image: redis
|
||||||
|
|
@ -20,7 +20,9 @@ services:
|
||||||
- 6380:6379
|
- 6380:6379
|
||||||
|
|
||||||
gotrue:
|
gotrue:
|
||||||
image: supabase/gotrue
|
build:
|
||||||
|
context: .
|
||||||
|
dockerfile: docker/gotrue.Dockerfile
|
||||||
restart: on-failure
|
restart: on-failure
|
||||||
depends_on:
|
depends_on:
|
||||||
- postgres
|
- postgres
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
FROM golang
|
||||||
|
WORKDIR /go/src/supabase
|
||||||
|
RUN git clone https://github.com/supabase/gotrue.git
|
||||||
|
WORKDIR /go/src/supabase/gotrue
|
||||||
|
RUN git checkout v2.95.2 && go install
|
||||||
|
CMD ["gotrue"]
|
||||||
|
|
@ -80,7 +80,7 @@ impl Client {
|
||||||
access_token,
|
access_token,
|
||||||
token_type: token_type.ok_or(url_missing_param("token_type"))?,
|
token_type: token_type.ok_or(url_missing_param("token_type"))?,
|
||||||
expires_in: expires_in.ok_or(url_missing_param("expires_in"))?,
|
expires_in: expires_in.ok_or(url_missing_param("expires_in"))?,
|
||||||
expires_at,
|
expires_at: expires_at.ok_or(url_missing_param("expires_at"))?,
|
||||||
refresh_token: refresh_token.ok_or(url_missing_param("refresh_token"))?,
|
refresh_token: refresh_token.ok_or(url_missing_param("refresh_token"))?,
|
||||||
user,
|
user,
|
||||||
provider_access_token,
|
provider_access_token,
|
||||||
|
|
|
||||||
|
|
@ -70,7 +70,7 @@ pub struct AccessTokenResponse {
|
||||||
pub access_token: String,
|
pub access_token: String,
|
||||||
pub token_type: String,
|
pub token_type: String,
|
||||||
pub expires_in: i64,
|
pub expires_in: i64,
|
||||||
pub expires_at: Option<i64>, // older versions of GoTrue do not return this
|
pub expires_at: i64,
|
||||||
pub refresh_token: String,
|
pub refresh_token: String,
|
||||||
pub user: User,
|
pub user: User,
|
||||||
pub provider_access_token: Option<String>,
|
pub provider_access_token: Option<String>,
|
||||||
|
|
@ -106,8 +106,8 @@ pub struct GoTrueSettings {
|
||||||
pub mailer_autoconfirm: bool,
|
pub mailer_autoconfirm: bool,
|
||||||
pub phone_autoconfirm: bool,
|
pub phone_autoconfirm: bool,
|
||||||
pub sms_provider: String,
|
pub sms_provider: String,
|
||||||
pub mfa_enabled: Option<bool>, // older versions of GoTrue do not return this
|
pub mfa_enabled: bool,
|
||||||
pub saml_enabled: Option<bool>, // older versions of GoTrue do not return this
|
pub saml_enabled: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
|
|
|
||||||
|
|
@ -53,14 +53,16 @@ impl From<anyhow::Error> for AppError {
|
||||||
#[cfg(feature = "cloud")]
|
#[cfg(feature = "cloud")]
|
||||||
impl From<gotrue_entity::GoTrueError> for AppError {
|
impl From<gotrue_entity::GoTrueError> for AppError {
|
||||||
fn from(err: gotrue_entity::GoTrueError) -> Self {
|
fn from(err: gotrue_entity::GoTrueError) -> Self {
|
||||||
match err.code {
|
match (err.code, err.msg.as_str()) {
|
||||||
401 => AppError::new(ErrorCode::OAuthError, err.msg),
|
(401, _) => AppError::new(ErrorCode::OAuthError, err.msg),
|
||||||
|
(422, "New password should be different from the old password.") => {
|
||||||
|
AppError::new(ErrorCode::InvalidPassword, err.msg)
|
||||||
|
},
|
||||||
_ => AppError::new(
|
_ => AppError::new(
|
||||||
ErrorCode::Unhandled,
|
ErrorCode::Unhandled,
|
||||||
format!(
|
format!(
|
||||||
"gotrue error: {}, id: {}",
|
"gotrue error: {}, message: {}, id: {:?}",
|
||||||
err.code,
|
err.code, err.msg, err.error_id,
|
||||||
err.error_id.unwrap_or("".to_string())
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -73,7 +73,9 @@ async fn sign_in_with_url() {
|
||||||
Ok(()) => panic!("should not be ok"),
|
Ok(()) => panic!("should not be ok"),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
assert_eq!(e.code, ErrorCode::OAuthError);
|
assert_eq!(e.code, ErrorCode::OAuthError);
|
||||||
assert!(e.message.starts_with("Invalid token: token is expired by"));
|
assert!(e
|
||||||
|
.message
|
||||||
|
.starts_with("invalid JWT: unable to parse or verify signature, token is expired by"));
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
use shared_entity::error_code::ErrorCode;
|
||||||
|
|
||||||
use crate::client::utils::{
|
use crate::client::utils::{
|
||||||
generate_unique_email, REGISTERED_EMAIL, REGISTERED_PASSWORD, REGISTERED_USER_MUTEX,
|
generate_unique_email, REGISTERED_EMAIL, REGISTERED_PASSWORD, REGISTERED_USER_MUTEX,
|
||||||
};
|
};
|
||||||
|
|
@ -20,9 +22,16 @@ async fn update_password_same_password() {
|
||||||
c.sign_in_password(®ISTERED_EMAIL, ®ISTERED_PASSWORD)
|
c.sign_in_password(®ISTERED_EMAIL, ®ISTERED_PASSWORD)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
c.update(®ISTERED_EMAIL, ®ISTERED_PASSWORD)
|
let err = c
|
||||||
|
.update(®ISTERED_EMAIL, ®ISTERED_PASSWORD)
|
||||||
.await
|
.await
|
||||||
|
.err()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
assert_eq!(err.code, ErrorCode::InvalidPassword);
|
||||||
|
assert_eq!(
|
||||||
|
err.message,
|
||||||
|
"New password should be different from the old password."
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue