Hey guys. I have a question regarding the “Edge se...
# ory-network
b
Hey guys. I have a question regarding the “Edge session” feature. I have enabled it ( project in https://console.ory.sh/ ) and i coded the nextjs app with:
Copy code
const ory = new FrontendApi(new Configuration(edgeConfig))
ory
            .toSession(undefined, {
                headers: {
                    "Cache-Control": "max-age=60",
                },
            })
            .then(({ data }) => {
}
but i can’t see any improvements in loading time ( sessions/whoami request still loading in ~ 500 ms ). I think that the docs at https://www.ory.sh/docs/concepts/cache#configuration ar a bit old, as my ory code from above is a bit different that in the docs. Could i miss something? ( add the header to the request and enable edge sessions on the project )
h
Can you provide more context please? For example your project URL?
b
XXX
h
Interesting, our service provider recently changed something in the way the DNS resolution works. I can also see that the cache is not being hit properly
if the cache was hit, it should have a response header of
*cf-cache-status:* HIT
which works for the main project we have (so for ory console), but apparently not on your custom domain 🤔
yeah, definitely related to that
thank you for bringing this to our attention, I’ll track this in our issue back log. it seem to work for oryapis.com domains but seems to have problems on custom domains
this stuff is unfortunately really difficult to test e2e 😞 but we’ll definitely also increase the test coverage to include custom domains
b
thank you! not a big issue for now for us, but would help a lot to lower the 500 ms to 50 ms in prod 🙂
h
yeah, absolutely. if you want, you can check console.ory.sh the network tab in chrome and search for
whoami
. that is the performance you can expect once this works on your custom domain
ok, i think i found the problem
can you try again?
b
did a logout/login before this. no changes in response time
h
try omitting the max age briefly, you can add it later again
here’s mine, it took 30ms
if you hit ctrl+r in the browser it always sends max-age=0 btw
b
so, i’m getting this when i do: https://auth.openline.ai/sessions/whoami
and the below times in my nextjs app deployed in vercel:
still getting cf-cache-status: MISS when i do the request against https://auth.openline.ai/sessions/whoami with or without Cache-Control header
h
So here’s what I do. I open https://auth.openline.ai/sessions/whoami in chrome, then i open chrome dev tools, then I copy & paste into the chrome console:
Copy code
await fetch("<https://auth.openline.ai/sessions/whoami>", {
  "headers": {
    "accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
    "accept-language": "de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7",
    "sec-ch-ua": "\"Not_A Brand\";v=\"99\", \"Google Chrome\";v=\"109\", \"Chromium\";v=\"109\"",
    "sec-ch-ua-mobile": "?0",
    "sec-ch-ua-platform": "\"macOS\"",
    "sec-fetch-dest": "document",
    "sec-fetch-mode": "navigate",
    "sec-fetch-site": "none",
    "sec-fetch-user": "?1",
    "upgrade-insecure-requests": "1"
  },
  "referrerPolicy": "strict-origin-when-cross-origin",
  "body": null,
  "method": "GET",
  "mode": "cors",
  "credentials": "include"
});
and repeat the fetch a couple of times, this gives me cache: hit
b
yes, indeed, that works. i’m getting cf-cache-status: HIT and a response in about 60 ms
ha, got you. so, when i do the request in browser ( just paste the URL and hit enter ) it’s adding: -H ‘cache-control: max-age=0’
h
exactly
b
Ok, but, the request done by the nextjs ory package receives: cf-cache-status: DYNAMIC
h
you mean ory/integrations?
ping @bulky-sundown-43494 🙂
b
Hey. I as able to hit the cache in my setup ( nextjs + vercel ) in the nextjs middleware. now i’m getting < 50ms response time
but on the frontend, using the ory/integrations i’m always receiving the cf-cache-status: DYNAMIC
h
ok so if you pass the request through
/.ory/sessions/whoami
it’s always dynamic right?
b
yes
h
ok got it 😕 originally, ory/integrations was built as a poc to figure out how to deal with these preview deployments. while it works quite well for testing and development, it’s problematic when used in production, because it routes all the traffic through one IP which essentially disables some of the security options we have. Plus, it does weird things like breaking the cache
We definitely should tell that to people and figure out what to do with this package 😕 /cc @magnificent-energy-493 is invested in this topic also
Plus things like social sign in don’t work (well) with ory/integrations
m
Maybe a notice on the README that its not meant to be used in production and can be removed once you add a CNAME? And then we add some to the docs as well, in the places where its used.
h
That sounds like a good way to do it! We also need to update our NextJS example in the docs though
👍 1
c
I am not able to replicate from the documentation for nextjs using Ory-integration. In my project slug social login is enabled. After signing it the attached error pops up. Why does Social sign in does not work with ory-integrations? What is an alternative way to do local development with nextjs?