Skip to content

Add session to endpoints #4068

Closed
Closed
@RaeesBhatti

Description

@RaeesBhatti

Describe the problem

Endpoints need to have access to user session to perform actions. Right now, you have to reimplement/import session management in endpoints.

Describe the proposed solution

Why not just expose session as part of Request to endpoints. We are already running getSession for pages. Let's run it for endpoints as well and have the results available in RequestEvent to endpoint handlers. e.g.

export const get: RequestHandler = async function({ url, session }) {
        if (!session.username) {
            status: 401,
            body: { error: "Unauthorized" }
        }
	return {
		body: { message: "ok" },
	};
};

Alternatives considered

No response

Importance

would make my life easier

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions