Prabha-AIMLOPS commited on
Commit
41c0b3a
·
1 Parent(s): 4459230

added additional parameters for token generation

Browse files
Files changed (1) hide show
  1. app/utils/auth_utils.py +9 -11
app/utils/auth_utils.py CHANGED
@@ -35,20 +35,18 @@ def validate_mobile(mobile: str) -> bool:
35
  """
36
  return mobile.isdigit() and len(mobile) == 10
37
 
38
- def generate_tokens(identifier: str) -> dict:
39
- """
40
- Generate access and refresh tokens.
41
-
42
- Args:
43
- identifier (str): Email or mobile number.
44
-
45
- Returns:
46
- dict: Access and refresh tokens.
47
- """
48
  access_token_expiry = datetime.utcnow() + timedelta(minutes=30)
49
  refresh_token_expiry = datetime.utcnow() + timedelta(days=1)
50
 
51
- access_token = jwt.encode({"sub": identifier, "exp": access_token_expiry}, SECRET_KEY, algorithm=ALGORITHM)
 
 
 
 
 
 
 
52
  refresh_token = jwt.encode({"sub": identifier, "exp": refresh_token_expiry}, SECRET_KEY, algorithm=ALGORITHM)
53
 
54
  return {"access_token": access_token, "refresh_token": refresh_token, "token_type": "bearer"}
 
35
  """
36
  return mobile.isdigit() and len(mobile) == 10
37
 
38
+ def generate_tokens(identifier: str, merchant_id: str = None, role: str = None) -> dict:
 
 
 
 
 
 
 
 
 
39
  access_token_expiry = datetime.utcnow() + timedelta(minutes=30)
40
  refresh_token_expiry = datetime.utcnow() + timedelta(days=1)
41
 
42
+ payload = {"sub": identifier, "exp": access_token_expiry}
43
+
44
+ if merchant_id:
45
+ payload["merchant_id"] = merchant_id
46
+ if role:
47
+ payload["role"] = role
48
+
49
+ access_token = jwt.encode(payload, SECRET_KEY, algorithm=ALGORITHM)
50
  refresh_token = jwt.encode({"sub": identifier, "exp": refresh_token_expiry}, SECRET_KEY, algorithm=ALGORITHM)
51
 
52
  return {"access_token": access_token, "refresh_token": refresh_token, "token_type": "bearer"}