Λ C Ξ L X R D
05/03/2022, 11:10 PMrp
05/04/2022, 4:31 AMΛ C Ξ L X R D
05/04/2022, 10:50 AMjs
import "https://cdn.jsdelivr.net/gh/supertokens/supertokens-website/bundle/bundle.js"
supertokens.init(
{
apiDomain: "http://localhost:8000",
apiBasePath: "/auth",
});
rp
05/04/2022, 10:50 AMΛ C Ξ L X R D
05/04/2022, 10:54 AMrp
05/04/2022, 10:55 AMΛ C Ξ L X R D
05/04/2022, 10:55 AMrp
05/04/2022, 10:55 AMverifySession
functionΛ C Ξ L X R D
05/04/2022, 10:55 AMrp
05/04/2022, 10:56 AMgetSession
Λ C Ξ L X R D
05/04/2022, 10:57 AMrp
05/04/2022, 10:57 AMSession.Error.TRY_REFRESH_TOKEN
, then you should send an HTML to the frontend which calls the attemptRefreshingSession
on the frontendΛ C Ξ L X R D
05/04/2022, 11:05 AMpy
@router.get("/dashboard", response_class=HTMLResponse)
async def dashboard_get(request: Request):
session = await get_session(request)
print(session)
if session is None:
print("No session")
return RedirectResponse("/")
else:
print("Session found")
rp
05/04/2022, 11:11 AMΛ C Ξ L X R D
05/04/2022, 11:11 AMrp
05/04/2022, 11:12 AMΛ C Ξ L X R D
05/04/2022, 11:14 AMrp
05/04/2022, 11:17 AMΛ C Ξ L X R D
05/04/2022, 11:19 AMrp
05/04/2022, 11:20 AMΛ C Ξ L X R D
05/04/2022, 11:21 AMINFO: 127.0.0.1:1188 - "GET /dashboard HTTP/1.1" 401 Unauthorized
com.supertokens {"t": "2022-05-04T11:20:42.978Z", "sdkVer": "0.6.5", "message": "middleware: Started", "file": "supertokens.py:339"}
com.supertokens {"t": "2022-05-04T11:20:42.978Z", "sdkVer": "0.6.5", "message": "middleware: Not handling because request path did not start with config path. Request path: /dashboard", "file": "supertokens.py:347"}
com.supertokens {"t": "2022-05-04T11:20:42.979Z", "sdkVer": "0.6.5", "message": "getSession: Started", "file": "recipe\\session\\recipe_implementation.py:134"}
com.supertokens {"t": "2022-05-04T11:20:42.979Z", "sdkVer": "0.6.5", "message": "getSession: rid in header: False", "file": "recipe\\session\\recipe_implementation.py:138"}
com.supertokens {"t": "2022-05-04T11:20:42.979Z", "sdkVer": "0.6.5", "message": "getSession: request method: GET", "file": "recipe\\session\\recipe_implementation.py:139"}
com.supertokens {"t": "2022-05-04T11:20:42.979Z", "sdkVer": "0.6.5", "message": "getSession: Returning try refresh token because access token from cookies is undefined", "file": "recipe\\session\\recipe_implementation.py:152"}
com.supertokens {"t": "2022-05-04T11:20:42.980Z", "sdkVer": "0.6.5", "message": "errorHandler: Started", "file": "supertokens.py:393"}
com.supertokens {"t": "2022-05-04T11:20:42.980Z", "sdkVer": "0.6.5", "message": "errorHandler: Error is from SuperTokens recipe. Message: Access token has expired. Please call the refresh API", "file": "supertokens.py:394"}
com.supertokens {"t": "2022-05-04T11:20:42.980Z", "sdkVer": "0.6.5", "message": "errorHandler: Checking recipe for match: session", "file": "supertokens.py:403"}
com.supertokens {"t": "2022-05-04T11:20:42.980Z", "sdkVer": "0.6.5", "message": "errorHandler: Matched with recipeID: session", "file": "supertokens.py:406"}
com.supertokens {"t": "2022-05-04T11:20:42.980Z", "sdkVer": "0.6.5", "message": "errorHandler: returning TRY_REFRESH_TOKEN", "file": "recipe\\session\\recipe.py:152"}
com.supertokens {"t": "2022-05-04T11:20:42.980Z", "sdkVer": "0.6.5", "message": "Sending response to client with status code: 401", "file": "utils.py:111"}
rp
05/04/2022, 11:21 AMpython
from supertokens_python.recipe.session.asyncio import get_session
from supertokens_python.recipe.session.exceptions import TryRefreshTokenError
async def dashboard_get(request: Request):
try:
session = await get_session(request)
print(session)
if session is None:
print("No session")
return RedirectResponse("/")
else:
print("Session found")
except TryRefreshTokenError:
print("need to refresh session")
# TODO: send back HTML to the frontend which will refresh the session
except
block needs to call supertokens.init
and then run supertokens.attemptRefreshingSession()
. If this is successful, you should simply reload the page, else you should redirect the user to the login pageΛ C Ξ L X R D
05/04/2022, 11:32 AMrp
05/04/2022, 11:32 AMΛ C Ξ L X R D
05/04/2022, 11:32 AMrp
05/04/2022, 11:32 AMΛ C Ξ L X R D
05/04/2022, 12:12 PMrp
05/04/2022, 12:12 PMΛ C Ξ L X R D
05/04/2022, 12:13 PMjs
<script>
supertokens.init(
{
apiDomain: "http://localhost:8000",
apiBasePath: "/auth",
}
);
supertokens.attemptRefreshingSession()
console.log("Session refreshed successfully");
window.location.href = "redirection url here"
</script>
rp
05/04/2022, 12:14 PM<script>
supertokens.init(
{
apiDomain: "http://localhost:8000",
apiBasePath: "/auth",
}
);
supertokens.attemptRefreshingSession().then(success => {
if (success) {
// reload page
} else {
// redirect to login page
}
})
</script>
Λ C Ξ L X R D
05/04/2022, 12:25 PMrp
05/04/2022, 12:25 PM