Skip to content

Commit

Permalink
+create user with other fields (#1790)
Browse files Browse the repository at this point in the history
  • Loading branch information
logerzerox authored Jan 10, 2025
1 parent badb168 commit a60d3b2
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 14 deletions.
15 changes: 12 additions & 3 deletions py/core/database/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,9 @@ async def create_user(
google_id: Optional[str] = None,
github_id: Optional[str] = None,
is_superuser: bool = False,
name: Optional[str] = None,
bio: Optional[str] = None,
profile_picture: Optional[str] = None
) -> User:
"""Create a new user."""
# 1) Check if a user with this email already exists
Expand Down Expand Up @@ -308,6 +311,9 @@ async def create_user(
"google_id": google_id,
"github_id": github_id,
"is_verified": account_type != "password",
"name": name,
"bio": bio,
"profile_picture": profile_picture,
}
)
.returning(
Expand All @@ -322,6 +328,9 @@ async def create_user(
"collection_ids",
"limits_overrides",
"metadata",
"name",
"bio",
"profile_picture",
]
)
.build()
Expand All @@ -345,9 +354,9 @@ async def create_user(
collection_ids=result["collection_ids"] or [],
limits_overrides=json.loads(result["limits_overrides"] or "{}"),
metadata=json.loads(result["metadata"] or "{}"),
name=None,
bio=None,
profile_picture=None,
name=result["name"],
bio=result["bio"],
profile_picture=result["profile_picture"],
account_type=account_type,
hashed_password=hashed_password,
google_id=google_id,
Expand Down
13 changes: 5 additions & 8 deletions py/core/main/api/v3/users_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,12 @@ def validate_password(password: str) -> bool:
# )

registration_response = await self.services.auth.register(
email, password
email=email,
password=password,
name=name,
bio=bio,
profile_picture=profile_picture
)
if name or bio or profile_picture:
return await self.services.auth.update_user(
user_id=registration_response.id,
name=name,
bio=bio,
profile_picture=profile_picture,
)

return registration_response

Expand Down
17 changes: 15 additions & 2 deletions py/core/main/services/auth_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,21 @@ def __init__(
)

@telemetry_event("RegisterUser")
async def register(self, email: str, password: str) -> User:
return await self.providers.auth.register(email, password)
async def register(
self,
email: str,
password: str,
name: Optional[str] = None,
bio: Optional[str] = None,
profile_picture: Optional[str] = None,
) -> User:
return await self.providers.auth.register(
email=email,
password=password,
name=name,
bio=bio,
profile_picture=profile_picture
)

@telemetry_event("SendVerificationEmail")
async def send_verification_email(
Expand Down
6 changes: 6 additions & 0 deletions py/core/providers/auth/r2r_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@ async def register(
account_type: str = "password",
github_id: Optional[str] = None,
google_id: Optional[str] = None,
name: Optional[str] = None,
bio: Optional[str] = None,
profile_picture: Optional[str] = None
) -> User:
if account_type == "password":
if not password:
Expand All @@ -228,6 +231,9 @@ async def register(
account_type=account_type,
github_id=github_id,
google_id=google_id,
name=name,
bio=bio,
profile_picture=profile_picture
)
default_collection: CollectionResponse = (
await self.database_provider.collections_handler.create_collection(
Expand Down
9 changes: 8 additions & 1 deletion py/core/providers/auth/supabase.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,14 @@ async def decode_token(self, token: str) -> TokenData:
"decode_token is not used with Supabase authentication"
)

async def register(self, email: str, password: str) -> User: # type: ignore
async def register(
self,
email: str,
password: str,
name: Optional[str] = None,
bio: Optional[str] = None,
profile_picture: Optional[str] = None
) -> User: # type: ignore
# Use Supabase client to create a new user

if user := self.supabase.auth.sign_up(email=email, password=password):
Expand Down

0 comments on commit a60d3b2

Please sign in to comment.