File size: 921 Bytes
ad87194
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import os
from fastapi import Depends
from supabase import create_client
from core import logging as logger
from core.utils.error_handling import create_error_response, raise_http_exception
from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer
from dotenv import load_dotenv
load_dotenv()

security = HTTPBearer()

supabase_client = create_client(
    os.getenv("SUPABASE_URL"),
    os.getenv("SUPABASE_KEY")
)


async def access_check_bearer(credentials: HTTPAuthorizationCredentials = Depends(security)):
    access_token = credentials.credentials
    try:
        supabase_client.auth.get_user(access_token)

    except Exception as e:
        logger.info(f">>> Invalid access token {e}<<<")
        raise_http_exception(code=401,
                                   message="Invalid Access Token", details=[
                {"info": "Invalid access token or access token expired please login again"}])