Skip to content

Commit 0a81238

Browse files
authored
docs(sveltekit): use auth over getSession (#9874)
fix: use `auth` over `getSession` Replaces `getSession` with `auth` given that `getSession` is now deprecated. Refer to: sveltejs/kit#5883 for context. The following PR also serves as context for the same milestone: sveltejs/kit#5946
1 parent c279bf2 commit 0a81238

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

docs/docs/getting-started/providers/oauth-tutorial.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -245,14 +245,14 @@ or https://generate-secret.vercel.app/32 to generate a random value for it.
245245

246246
### Exposing the session via page store
247247

248-
Auth.js provides us a getSession, function to access the session data and status, to call from the `event.locals` variable. We can now just call it and add it to our `$page` store.
248+
Auth.js provides us a `auth`, function to access the session data and status, to call from the `event.locals` variable. We can now just call it and add it to our `$page` store.
249249

250250
```ts
251251
import type { LayoutServerLoad } from "./$types"
252252

253253
export const load: LayoutServerLoad = async (event) => {
254254
return {
255-
session: await event.locals.getSession(),
255+
session: await event.locals.auth(),
256256
}
257257
}
258258
```
@@ -279,14 +279,14 @@ You can use the `$page.data.session` variable from anywhere on your page. Learn
279279

280280
### Protecting API Routes
281281

282-
To protect your API Routes (blocking unauthorized access to resources), you can use `locals.getSessions()` just like in the layouts file to know whether a session exists or not:
282+
To protect your API Routes (blocking unauthorized access to resources), you can use `locals.auth()` just like in the layouts file to know whether a session exists or not:
283283

284284
```ts title="routes/api/movies/+server.ts"
285285
import { json, error } from "@sveltejs/kit"
286286
import type { RequestEvent } from "./$types"
287287

288288
export async function GET({ locals }: RequestEvent) {
289-
const session = await locals.getSession()
289+
const session = await locals.auth()
290290
if (!session?.user) {
291291
throw error(401, "You must sign in to view movies.")
292292
}

0 commit comments

Comments
 (0)