Skip to content

How to Access request.session.get("xxx") in Marimo Notebook ? #3280

Closed Answered by SimonYang-CS
SimonYang-CS asked this question in Q&A
Discussion options

You must be logged in to vote

This issue has been fixed in 0.11.6.

  1. Add customer AuthMiddleware

`
class AuthMiddleware(BaseHTTPMiddleware):
async def dispatch(self, request: Request, call_next):
request.scope["user"] = {
"is_authenticated": True,
"username": "email",
}

    request.scope["meta"] = {
        "email": "god",
        "groups": ["admin", "user"],
    }

    print("in AuthMiddleware")
    return await call_next(request)

`

  1. Access data in notebook

`
@app.cell
def cell_user_group(mo):
meta = mo.app_meta().request.meta
email = meta.get("email")
groups = meta.get("groups")
meta_md = mo.md(f"meta email: {email} groups: {groups}")
meta_md

return email, groups

`

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@SimonYang-CS
Comment options

Answer selected by SimonYang-CS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants