https://www.ory.sh/ logo
#talk-kratos
Title
# talk-kratos
m

many-garden-6507

04/23/2022, 7:23 AM
Hi i am working on this part https://www.ory.sh/docs/guides/protect-page-login/next.js and getting session like this
ory
.toSession()
.then(({ data }) => {
// User has a session!
setSession(data)
})
._catch_(() => {
// Redirect to login page
_return_ router.push(edgeConfig.basePath + '/ui/login')
})
it takes some time to ensue if user is already loged in or not and during this time ui remains blank and than transitions to login page which is not smooth experience specially if i want to implement this in different pages, so my question is, is there other way to getting session which does not take much time?
or does the ory stores the session in cookie so that i can get it from there so it does not take much time.
@User @User
i am using default playground for ory kratos and when i try to use this approch to get session value
fetch(
'<https://playground.projects.oryapis.com/api/kratos/public/sessions/whoami>',
)
.then((res) => res.json())
.then((session) => console.log(session))
it gives cors origin error, i am running app locally
p

proud-plumber-24205

04/23/2022, 12:22 PM
Cors errors are due to your browser requesting resources from an origin that does not match your current browser origin is on e.g. your browser is on
<http://localhost:4000|http://localhost:4000>
however the origin you are requesting is on
https://<slug>.projects...com
To get around this you need to use the Ory cli proxy and have the proxy handle the traffic to the playground project as well as your application
3 Views