adyus3380
08/17/2022, 4:39 PMsIRTFrontend
keeps getting reset to remove
after logging in. I'm using code from the Vue.js example included in the web-js repo (https://github.com/supertokens/supertokens-web-js/tree/master/examples/vuejs/with-thirdpartyemailpassword), but with EmailPassword instead of ThirdPartyEmailPassword. That's the only code change from the sample>
I'm using a Python backend using FastAPI, running on http://localhost:8000
. Frontend is running at http://localhost:8080
. Here are my settings:
Frontend:
js
VITE_API_URL=http://localhost:8000
VITE_API_BASEPATH=/api/v1/auth
VITE_WEB_URL=http://localhost:8080
js
const apiDomain = import.meta.env.VITE_API_URL;
const apiBasePath = import.meta.env.VITE_API_BASEPATH;
SuperTokens.init({
appInfo: {
appName: "Test",
apiDomain,
apiBasePath,
},
recipeList: [Session.init(), EmailPassword.init()],
// enableDebugLogs: true,
});
Backend:
python
SUPERTOKENS_URL = os.environ.get("SUPERTOKENS_URL", "http://localhost:3567")
SUPERTOKENS_API_KEY = os.environ.get("SUPERTOKENS_API_KEY", "someRandomKey")
SUPERTOKENS_WEBSITE_DOMAIN = os.environ.get(
"SUPERTOKENS_WEBSITE_DOMAIN", "http://localhost:8080"
)
SUPERTOKENS_API_DOMAIN = os.environ.get(
"SUPERTOKENS_API_DOMAIN", "http://localhost:8000"
)
python
supertokens_init(
app_info=InputAppInfo(
app_name="Test",
api_domain=SUPERTOKENS_API_DOMAIN,
website_domain=SUPERTOKENS_WEBSITE_DOMAIN,
api_base_path="/api/v1/auth", # Remember to set this on the frontend as well
),
supertokens_config=SupertokensConfig(
connection_uri=SUPERTOKENS_URL, api_key=SUPERTOKENS_API_KEY
),
framework="fastapi",
recipe_list=[
st_session.init(), # initializes session features
st_emailpassword.init(),
st_userroles.init(),
],
mode="asgi",
)
adyus3380
08/17/2022, 4:40 PMpython
origins = [SUPERTOKENS_WEBSITE_DOMAIN]
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
# allow_methods=["*"],
allow_methods=["GET", "PUT", "POST", "DELETE", "OPTIONS", "PATCH"],
expose_headers=["X-Process-Time"],
# allow_headers=["*"],
allow_headers=get_all_cors_headers(),
)
adyus3380
08/17/2022, 4:41 PMopen -n -a /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --args --user-data-dir="/tmp/chrome_dev_test" --disable-web-security
under macOS) makes sessions work just fine, no issues.
But I'd like to develop using my regular browser, so I'm trying to figure out what's going on.adyus3380
08/17/2022, 4:42 PM401
at /api/v1/auth/session/refresh
when refreshing the webapp (after clearing cookies), so naturally sIRTFrontend
gets set to remove
again.adyus3380
08/17/2022, 4:45 PM/api/v1/auth/signin
is 200 and contains the id-refresh-token
header.adyus3380
08/17/2022, 4:47 PMrp_st
08/17/2022, 4:49 PMrp_st
08/17/2022, 4:49 PMadyus3380
08/17/2022, 4:49 PMrp_st
08/17/2022, 4:50 PMrp_st
08/17/2022, 4:50 PMrp_st
08/17/2022, 4:50 PMadyus3380
08/17/2022, 4:53 PMpython
com.supertokens {"t": "2022-08-17T16:52:03.231Z", "sdkVer": "0.10.2", "message": "middleware: Started", "file": "supertokens.py:394"}
com.supertokens {"t": "2022-08-17T16:52:03.231Z", "sdkVer": "0.10.2", "message": "middleware: requestRID is: session", "file": "supertokens.py:407"}
com.supertokens {"t": "2022-08-17T16:52:03.231Z", "sdkVer": "0.10.2", "message": "middleware: Checking recipe ID for match: session", "file": "supertokens.py:418"}
com.supertokens {"t": "2022-08-17T16:52:03.231Z", "sdkVer": "0.10.2", "message": "middleware: Matched with recipe ID: session", "file": "supertokens.py:440"}
com.supertokens {"t": "2022-08-17T16:52:03.231Z", "sdkVer": "0.10.2", "message": "middleware: Request being handled by recipe. ID is: /session/refresh", "file": "supertokens.py:452"}
com.supertokens {"t": "2022-08-17T16:52:03.232Z", "sdkVer": "0.10.2", "message": "refreshSession: Started", "file": "recipe/session/recipe_implementation.py:245"}
adyus3380
08/17/2022, 4:53 PMpython
com.supertokens {"t": "2022-08-17T16:52:03.232Z", "sdkVer": "0.10.2", "message": "refreshSession: UNAUTHORISED because idRefreshToken from cookies is undefined", "file": "recipe/session/recipe_implementation.py:249"}
com.supertokens {"t": "2022-08-17T16:52:03.232Z", "sdkVer": "0.10.2", "message": "errorHandler: Started", "file": "supertokens.py:468"}
com.supertokens {"t": "2022-08-17T16:52:03.232Z", "sdkVer": "0.10.2", "message": "errorHandler: Error is from SuperTokens recipe. Message: Session does not exist. Are you sending the session tokens in the request as cookies?", "file": "supertokens.py:469"}
com.supertokens {"t": "2022-08-17T16:52:03.232Z", "sdkVer": "0.10.2", "message": "errorHandler: Checking recipe for match: session", "file": "supertokens.py:480"}
com.supertokens {"t": "2022-08-17T16:52:03.232Z", "sdkVer": "0.10.2", "message": "errorHandler: Matched with recipeID: session", "file": "supertokens.py:486"}
com.supertokens {"t": "2022-08-17T16:52:03.232Z", "sdkVer": "0.10.2", "message": "errorHandler: returning UNAUTHORISED", "file": "recipe/session/recipe.py:210"}
com.supertokens {"t": "2022-08-17T16:52:03.232Z", "sdkVer": "0.10.2", "message": "Sending response to client with status code: 401", "file": "utils.py:123"}
INFO: 127.0.0.1:55406 - "POST /api/v1/auth/session/refresh HTTP/1.1" 401 Unauthorized
adyus3380
08/17/2022, 4:53 PMCookie: sRefreshToken="9ESH0dKRXoHfx/HYSqiJm0pOtExnDCi5djAzg3okc/y4kyFZ6U5IQ5jYEFYO7ocdXGL3xDMG10QnVChpH2l7DZdIsRitFCWCjmDAnsGOtadjBcOZecngXPzkH3fm3xkV/t75McfHWmQ6eSjbhVo8tYFhX/F2OMa2kal5W54H20Y/kjW6tcNKhAjlP64ekDSvj11NYzgAJ1qJ6Gz%2BwOq1wi0wYxwGWz50DHBQuzHGnWMbWHuaf0R%2BPBSmL3TcZjuvidJM0l0N%2BJs8NDq9qBZY.b63b955f264501e6e0f383647bf279090ad2bac85be78de7aa92f42c90af9560.V2"
adyus3380
08/17/2022, 4:54 PMrp_st
08/17/2022, 4:57 PMadyus3380
08/17/2022, 4:58 PMrp_st
08/17/2022, 4:58 PMrp_st
08/17/2022, 4:59 PMadyus3380
08/17/2022, 4:59 PMrp_st
08/17/2022, 4:59 PMadyus3380
08/17/2022, 5:00 PMrp_st
08/17/2022, 5:00 PMrp_st
08/17/2022, 5:00 PMrp_st
08/17/2022, 5:00 PMadyus3380
08/17/2022, 5:01 PMrp_st
08/17/2022, 5:01 PMlocalhost:8000/api/v1/auth/session/refresh
-> do you see a refresh token in the cookie store?adyus3380
08/17/2022, 5:03 PMrp_st
08/17/2022, 5:03 PMadyus3380
08/17/2022, 5:05 PMrp_st
08/17/2022, 5:05 PMadyus3380
08/17/2022, 5:05 PMadyus3380
08/17/2022, 5:06 PMrp_st
08/17/2022, 5:06 PMadyus3380
08/17/2022, 5:07 PMrp_st
08/17/2022, 5:07 PMrp_st
08/17/2022, 5:07 PMadyus3380
08/17/2022, 5:07 PMadyus3380
08/17/2022, 5:07 PMrp_st
08/17/2022, 5:07 PMadyus3380
08/17/2022, 5:08 PMadyus3380
08/17/2022, 5:08 PMrp_st
08/17/2022, 5:08 PMrp_st
08/17/2022, 5:08 PMadyus3380
08/17/2022, 5:08 PMrp_st
08/17/2022, 5:09 PMadyus3380
08/17/2022, 5:09 PMrp_st
08/17/2022, 5:09 PMrp_st
08/17/2022, 5:09 PMadyus3380
08/17/2022, 5:09 PMadyus3380
08/17/2022, 5:10 PMadyus3380
08/17/2022, 5:10 PMrp_st
08/17/2022, 5:10 PMadyus3380
08/17/2022, 5:11 PMPath=/
on sIdRefreshToken?rp_st
08/17/2022, 5:11 PMadyus3380
08/17/2022, 5:11 PMadyus3380
08/17/2022, 5:11 PMrp_st
08/17/2022, 5:12 PMrp_st
08/17/2022, 5:12 PMadyus3380
08/17/2022, 5:12 PMrp_st
08/17/2022, 5:12 PMadyus3380
08/17/2022, 5:12 PMrp_st
08/17/2022, 5:13 PMadyus3380
08/17/2022, 5:13 PMadyus3380
08/17/2022, 5:13 PMrp_st
08/17/2022, 5:14 PMadyus3380
08/17/2022, 5:14 PMadyus3380
08/17/2022, 5:14 PMrp_st
08/17/2022, 5:15 PMadyus3380
08/17/2022, 5:15 PMrp_st
08/17/2022, 5:15 PMrp_st
08/17/2022, 5:15 PMadyus3380
08/17/2022, 5:17 PMadyus3380
08/17/2022, 5:19 PMsIRTFrontend
with the sIdRefreshToken
value only sorta works. The home route doesn't redirect to /auth anymore, but neither does it progress past Session.doesSessionExist()
rp_st
08/17/2022, 5:20 PMrp_st
08/17/2022, 5:21 PMAccess-Control-Expose-Headers: front-token, id-refresh-token
in the response headers.rp_st
08/17/2022, 5:21 PMrp_st
08/17/2022, 5:23 PMorigins = [SUPERTOKENS_WEBSITE_DOMAIN]
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
# allow_methods=["*"],
allow_methods=["GET", "PUT", "POST", "DELETE", "OPTIONS", "PATCH"],
expose_headers=["X-Process-Time"],
# allow_headers=["*"],
allow_headers=get_all_cors_headers(),
)
code is setting the Access-Control-Expose-Headers
to always only have X-Process-Time
regardless of what the SDK sets in the response for the API that it controls.adyus3380
08/17/2022, 5:23 PMadyus3380
08/17/2022, 5:23 PMrp_st
08/17/2022, 5:23 PMexpose_headers=["X-Process-Time", "front-token", "id-refresh-token"],
adyus3380
08/17/2022, 5:24 PMadyus3380
08/17/2022, 5:24 PMrp_st
08/17/2022, 5:24 PMCORSMiddleware
, then why do you also need to add the other items in the code?adyus3380
08/17/2022, 5:25 PMX-Process-Time
as a frontend-facing performance metricrp_st
08/17/2022, 5:25 PMadyus3380
08/17/2022, 5:25 PMpython
@app.middleware("http")
async def add_process_time_header(request: Request, call_next):
start_time = time.time()
response = await call_next(request)
process_time = time.time() - start_time
response.headers["X-Process-Time"] = str(round(process_time, 3))
return response
rp_st
08/17/2022, 5:26 PMadyus3380
08/17/2022, 5:26 PMadyus3380
08/17/2022, 5:26 PMrp_st
08/17/2022, 5:26 PMAccess control expose headers not set properly - which prevents frontend from reading the id-refresh-token, which prevents setting that state on the frontend.
rp_st
08/17/2022, 5:27 PMadyus3380
08/17/2022, 5:30 PMexpose_headers
works with my custom header, whereas expose_headers = ["*"]
doesn't work, browsers hate the star on insecure connections.
Anyway, thanks for sorting me out. Have a great day!rp_st
08/17/2022, 5:30 PM