acoustic-insurance-23566
10/12/2023, 8:05 PMproud-plumber-24205
10/13/2023, 9:47 AMacoustic-insurance-23566
10/13/2023, 11:27 AMlist
is a request to our backend where our backend will authenticate the user, it's issued every 10 seconds (think of it as a heartbeat). whoami
is direct call to Kratos. In this example, I have deleted the user account after the second list
request after the first whoami
request. After that, you can see a few successful list
requests, a failed list
request, a successful whoami
request, successful list
request and further failed list
requests.acoustic-insurance-23566
10/13/2023, 11:28 AMlist
request after the first whoami
call. Here you can observe that list
requests started to fail immediately (good) but subsequent whoami
call succeeds along with a few list
requests further down.acoustic-insurance-23566
10/13/2023, 11:28 AMacoustic-insurance-23566
10/13/2023, 11:39 AMlist
call after the first whoami
call. This is pretty much what I'd expect.
I understand there might be some eventual consistency mechanism to invalidate the cache, but it looks like it takes you more than 2 minutes to reach consistency, which feels a bit much...steep-lamp-91158
steep-lamp-91158
steep-lamp-91158
steep-lamp-91158
high-optician-2097
ory.toSession(undefined, undefined, {
headers: {
"Cache-Control": "max-age=10",
},
})
Flooding the whoami endpoint with additional calls is NOT the best way to invalidate the cache! In fact, it might lead to issues.acoustic-insurance-23566
10/13/2023, 12:17 PMacoustic-insurance-23566
10/13/2023, 1:50 PMimport { Configuration, FrontendApi } from "<@U010S8T03NG>/client";
const kratos = new FrontendApi(
new Configuration({
basePath: KRATOS_HOSTNAME,
baseOptions: {
// Ensures we send cookies in the CORS requests.
withCredentials: true,
},
})
);
const test = await kratos.toSession(undefined, undefined, {
headers: {
"Cache-Control": "max-age=60",
},
});
but this throws a build error
(...).ts:36:54 - error TS2554: Expected 0-2 arguments, but got 3.
36 await kratos.toSession(undefined, undefined, {
~
37 headers: {
~~~~~~~~~~~~~~~~~~~~~~
...
39 },
~~~~~~~~~~~~~~
40 });
~~~~~~~~~
Found 1 error in (...).ts:36
TS hints that the method signature is FrontendApi.toSession(requestParameters?: FrontendApiToSessionRequest | undefined, options?: AxiosRequestConfig | undefined): Promise<AxiosResponse<Session>>
If I try like
await kratos.toSession(undefined, {
headers: {
"Cache-Control": "max-age=60",
},
});
it builds and makes the request, but it is stripped of some other headers so it causes a CORS error. It looks like I have version 1.2.11
of the SDK, which is the latest 🤔
attached screenshot of how this /whoami
request looks like, we're using the Ory Tunnel for local dev here. The request works fine if I call it without arguments, like kratos.toSession()
or even kratos.toSession(undefined)
acoustic-insurance-23566
10/19/2023, 1:03 PMsteep-lamp-91158
transformRequest
would be a way to extend the already set headers, instead of replacing allsteep-lamp-91158
acoustic-insurance-23566
10/19/2023, 4:35 PMfetch
requests, one with the extra header and one without. A plain fetch
request works fine - returns a 401 as expected. But if I add the Cache-Control
header to the request, the request is blocked by CORS policy.
The result is the same if I am logged in and set the credentials: "include"
option. Then I get a correct 200 without the extra header and a CORS error if I set the Cache-Control
header