Skip to content

Instantly share code, notes, and snippets.

@mtt87
Created September 6, 2021 12:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mtt87/129ec5d99029958a83311cd0f29abb42 to your computer and use it in GitHub Desktop.
Save mtt87/129ec5d99029958a83311cd0f29abb42 to your computer and use it in GitHub Desktop.
import 'navigator.locks'
export async function getSession(ctx) {
if (typeof window === 'undefined') {
const session = await _fetchData("session", ctx)
return session
}
return navigator.locks.request('NEXT_AUTH:GET_SESSION', async () => {
const session = await _fetchData("session", ctx)
if (ctx?.triggerEvent ?? true) {
broadcast.post({ event: "session", data: { trigger: "getSession" } })
}
return session
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment