Skip to content

Thông tin user-service (Dịch vụ người dùng)

Mục đích: xác thực & quản lý hồ sơ người dùng (supabase)

Storage Bucket avatars lưu trữ vật lý các file ảnh đại diện do người dùng tải lên.

Do mỗi lần user đăng nhập lại, Supabase/Google sẽ ghi đè lại thông tin gốc. Do đó, bảng profiles lưu trữ thông tin người dùng cập nhật.

Đăng nhập qua Google OAuth

REQUEST:

https://[PROJECT_REF].supabase.co/auth/v1/authorize?provider=google

RESPONSE:

access_token=...&expires_at=...&expires_in=...&provider_token=...&refresh_token=...&sb=&token_type=bearer

Refresh Token để cấp lại Access Token mới khi hết hạn

REQUEST:

curl --location 'https://[PROJECT_REF].supabase.co/auth/v1/token?grant_type=refresh_token' \ --header 'apikey: ...' \ --header 'Content-Type: application/json' \ --data '{ "refresh_token": "..." }'

RESPONSE:

{ "access_token": "...", "token_type": "bearer", "expires_in": 43200, "expires_at": 1776089711, "refresh_token": "...", "user": ... }

Lấy thông tin người dùng từ bảng profiles

REQUEST:

curl --location 'https://[PROJECT_REF].supabase.co/rest/v1/profiles?id=eq.54b49784-e5ab-4ad4-bcce-5a915d09d67c' \ --header 'apikey: ...'

RESPONSE:

[ { "id": "54b49784-e5ab-4ad4-bcce-5a915d09d67c", "full_name": "Nghia Admin", "avatar_url": "https://api.20206205.tech/api/dev/supabase/storage/v1/object/public/avatars/54b49784-e5ab-4ad4-bcce-5a915d09d67c_iyv5smdha8.png" } ]

Tải ảnh lên Supabase Storage bucket avatars

REQUEST:

curl --location 'https://[PROJECT_REF].supabase.co/storage/v1/object/avatars/54b49784-e5ab-4ad4-bcce-5a915d09d67c_082a9073-aeb3-44d5-bf23-f994c907a389.jpg' \ --header 'apikey: ...' \ --header 'Authorization: Bearer ...' \ --header 'Content-Type: image/png' \ --data-raw '@/c:/Users/Admin/Desktop/20206205/test/image/download.jpg'

RESPONSE:

{ "Key": "avatars/54b49784-e5ab-4ad4-bcce-5a915d09d67c_082a9073-aeb3-44d5-bf23-f994c907a389.jpg", "Id": "8d2dc9c6-938b-4d38-9d2e-81b3f2c20707" }

REQUEST:

curl --location 'https://[PROJECT_REF].supabase.co/storage/v1/object/avatars/54b49784-e5ab-4ad4-bcce-5a915d09d67c_082a9073-aeb3-44d5-bf23-f994c907a389.jpg'

Cập nhật thông tin Tên (Name) hoặc đường dẫn ảnh (Avatar URL)

REQUEST:

curl --location --request PATCH 'https://[PROJECT_REF].supabase.co/rest/v1/profiles?id=eq.54b49784-e5ab-4ad4-bcce-5a915d09d67c' \ --header 'apikey: ...' \ --header 'Authorization: Bearer ...' \ --header 'Prefer: return=representation' \ --header 'Content-Type: application/json' \ --data '{ "full_name": "Nghia dev 123", "avatar_url": "https://api.20206205.tech/api/dev/supabase/storage/v1/object/public/avatars/54b49784-e5ab-4ad4-bcce-5a915d09d67c_iyv5smdha8.png" }'

RESPONSE:

[ { "id": "54b49784-e5ab-4ad4-bcce-5a915d09d67c", "full_name": "Nghia dev 123", "avatar_url": "https://api.20206205.tech/api/dev/supabase/storage/v1/object/public/avatars/54b49784-e5ab-4ad4-bcce-5a915d09d67c_iyv5smdha8.png" } ]

Cấu hình trong Kong API Gateway

Tạo services có url là https://[PROJECT_REF].supabase.co Tạo routes có paths[] là /api/dev/supabase và /api/prod/supabase Tạo request-transformer có header=apikey:...