-
-
Notifications
You must be signed in to change notification settings - Fork 101
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
Add sessions #508
Add sessions #508
Conversation
* Allow passing session data to the fetch function * Prefer the client side session * Receive the server session only in the browser * Separate client and server sessions more clearly * make test more resilient * fake root layout file * fake +layout.server.js * kit transform threads session from +layout.server.js to client * remove client.init Co-authored-by: Andreas Fehn <[email protected]>
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
🦋 Changeset detectedLatest commit: a952aeb The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
does this need to use hooks? I think the page data is available to all children? Rich's post on the "removing sessions" discussion mentions doing like: // src/routes/+layout.server.ts
import type { LayoutServerLoad } from "./$types"
export const load: LayoutServerLoad = async function ({ request }) {
return {
token: request.headers.get("Authorization"),
}
} am I missing something? |
You are right, you can get the token like this. But then, you have to pass it all the time "manually" to do graphql operations. // +page.ts _pseudo code_
export const load: PageLoad = async (event) => {
const { token } = await event.parent();
GQL_GetUser.fetch({ variables: xxx, metadata: { token } })
} // client.ts _pseudo code_
import type { RequestHandlerArgs } from '$houdini'
import { HoudiniClient } from '$houdini'
async function fetchQuery({ fetch, text = '', variables = {}, metadata}: RequestHandlerArgs) {
const url = 'http://.../graphql'
const result = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${metadata?.token}`
},
body: JSON.stringify({
query: text,
variables
})
})
return await result.json()
}
export default new HoudiniClient(fetchQuery) You have to do it like this because we can't know that you will name your token. That's a lot of constraints. But it's possible 👍 With // +page.ts _pseudo code_
export const load: PageLoad = async (event) => {
GQL_GetUser.fetch({ variables: xxx })
} It improves the DX a lot I think 👍 |
Theoretically you could have it so the user passes a function that takes load args and produces a token, but I do think your method is sound. On another topic, I'm concerned about how to set this manually, for logins and logouts. Would this function off cookies or something more advanced? |
I would like to provide few complete guides later on these common topics 👌 |
Nice work! |
I'm going to merge this so I can deploy a new version and finally start migrating my applications to the new svelte kit and houdini 🎉 Thanks again everyone for all the help! |
Docs coming soon? |
Actually, all PR has their own docs (check on top "the Vercel preview") In general |
This is a continuation of @fehnomenal's work in #489 that started the support for user-based sessions (ie, authentication). There are 2 parts to this feature:
hooks.js
using the houdini client's newsetSession(event, { ... })
methodTo help everyone out, please make sure your PR does the following:
pnpm run tests
andcd integration && pnpm run tests
pnpm changeset
What's left
todo
)client.init
client.init
App.Session
typeonError
client side navgiation integration tests should fail