-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5e5baec
commit 4e9959f
Showing
6 changed files
with
171 additions
and
34 deletions.
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
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 |
---|---|---|
@@ -1,8 +1,9 @@ | ||
export interface User { | ||
id: number; | ||
id: string; | ||
firstName: string; | ||
lastName: string; | ||
photoUrl: string; | ||
username: string; | ||
email: string; | ||
status: 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,25 @@ | ||
from app.database.supabase_connection import get_supabase_admin_client | ||
from app.data_models import AuthenticationError | ||
from app.data_models import AuthenticationError, UserModel | ||
from app.mapper.mapper import supabase_user_to_python_user | ||
|
||
|
||
def fetch_supabase_user(salesforce_id: str): | ||
def fetch_supabase_user(salesforce_id: str) -> UserModel: | ||
try: | ||
service_supabase = get_supabase_admin_client() | ||
|
||
# Fetch all users | ||
response = service_supabase.auth.admin.list_users() | ||
supabase_user = None | ||
# Find the user with matching salesforce_id in user metadata | ||
for user in response: | ||
if ( | ||
user.user_metadata | ||
and user.user_metadata.get("salesforce_id") == salesforce_id | ||
): | ||
supabase_user = user | ||
# Query the User table for the specific salesforce_id | ||
response = ( | ||
service_supabase.table("User") | ||
.select("*") | ||
.eq("salesforce_id", salesforce_id) | ||
.execute() | ||
) | ||
|
||
if response.data and len(response.data) > 0: | ||
supabase_user = response.data[0] | ||
return supabase_user_to_python_user(supabase_user) | ||
else: | ||
return None | ||
|
||
return supabase_user | ||
except Exception as e: | ||
raise AuthenticationError(f"Failed to fetch Supabase user ID: {str(e)}") | ||
raise AuthenticationError(f"Failed to fetch Supabase user: {str(e)}") |
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