Spaces:
Paused
Paused
Download tmp_get_token.py from TeamError404/nexus: direct link, hf CLI and curl.
- Browser
- Download file 967 Bytes
-
https://huggingface.co/spaces/TeamError404/nexus/resolve/main/tmp_get_token.py
- Command line
-
hf download hf://spaces/TeamError404/nexus/tmp_get_token.py
-
curl -L -o tmp_get_token.py https://huggingface.co/spaces/TeamError404/nexus/resolve/main/tmp_get_token.py
967 Bytes
| import asyncio | |
| from core.security import create_access_token | |
| from core.database import async_session_factory | |
| from sqlalchemy import select | |
| from models.user import User, UserRole | |
| from models.user_workspace import UserWorkspace | |
| async def get_token(): | |
| async with async_session_factory() as db: | |
| # Fetch ANSELL ADMIN | |
| u_res = await db.execute(select(User).where(User.email == "admin@ansell.com")) | |
| user = u_res.scalar_one_or_none() | |
| if not user: | |
| print("User not found") | |
| return | |
| # Fetch association | |
| assoc_res = await db.execute(select(UserWorkspace).where(UserWorkspace.user_id == user.id)) | |
| assoc = assoc_res.scalar_one_or_none() | |
| token = create_access_token( | |
| subject=str(user.id), | |
| workspace_id=str(assoc.workspace_id), | |
| role=assoc.role | |
| ) | |
| print(f"TOKEN: {token}") | |
| if __name__ == "__main__": | |
| asyncio.run(get_token()) | |