Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A way to get the user object in +server.ts via the POST method #49

Open
Tilo-K opened this issue Feb 20, 2024 · 2 comments
Open

A way to get the user object in +server.ts via the POST method #49

Tilo-K opened this issue Feb 20, 2024 · 2 comments

Comments

@Tilo-K
Copy link

Tilo-K commented Feb 20, 2024

It would be really great if the user object was available inside the POST function of +server.ts

async function POST(event: RequestEvent)

currently event.locals does not contain anything.

Is there any for me to do this or for you to add this?

@ricardo-rp
Copy link

Make a PR bro

@wobsoriano
Copy link

When this PR gets merged, you can do it like this:

import { redirect } from '@sveltejs/kit'
import { clerkClient } from 'svelte-clerk/server'

export const load = ({ locals }) => {
	if (!locals.auth.userId) {
		return redirect(307, '/sign-in')
	}

	const user = await clerkClient.users.getUser(userId)

	return {
		user: JSON.parse(JSON.stringify(user)),
	}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants