File size: 925 Bytes
a4a2363
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
29
30
"""
Created By: ishwor subedi
Date: 2024-09-03
"""
import os
from fastapi import Depends
from supabase import create_client
from src import logging as logger
from src.utils.error_handling import create_error_response, raise_http_exception
from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer

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"}])