Skip to content

Allow a token string to be passed into createSvelteAuthClient #11

@Tyler-Petrov

Description

@Tyler-Petrov

The access token can be retrieved server side. Because createSvelteAuthClient doesn't except a token as input there's no way to use the client during SSR. If the token is passed in (event if undefined/null) the token shouldn't be fetched. I don't see any reason that this wouldn't be the preferred happy path moving forward.

I would love to see this:

layout.server.ts

import type { LayoutServerLoad } from './$types';

export const load = (async ({ locals: { token } }) => {
    return {
        token
    };
}) satisfies LayoutServerLoad;

layout.svete (root)

<script lang="ts">
  import '../app.css';
  import favicon from '$lib/assets/favicon.svg';
  import { createSvelteAuthClient } from '@mmailaender/convex-better-auth-svelte/svelte'; 
  import { authClient } from '$lib/auth-client'; 

  let { children, data } = $props();

  createSvelteAuthClient({
    authClient,
    options: {
      token: data.token
    }
  }); 
</script>

<svelte:head>
  <link rel="icon" href={favicon} />
</svelte:head>

{@render children?.()}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions