Hooks: Add request event handler for authentication
This commit is contained in:
19
src/routes/+layout.server.ts
Normal file
19
src/routes/+layout.server.ts
Normal file
@ -0,0 +1,19 @@
|
||||
import type { LayoutServerLoad } from "./$types";
|
||||
|
||||
// On each page load (every route), this function runs serverside.
|
||||
// The "locals.user" object is only available on the server,
|
||||
// since it's populated inside hooks.server.ts.
|
||||
// It will populate the "user" attribute of each page's "data" object,
|
||||
// so each page has access to the current user (or knows if no one is signed in).
|
||||
export const load: LayoutServerLoad = ({ locals }) => {
|
||||
if (locals.user) {
|
||||
return {
|
||||
user: locals.user,
|
||||
admin: locals.user.admin,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
user: undefined,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user