title: How to pass data from endpoint to getSession() in SvelteKit?
body: <p>I am trying to pass an object from endpoint to <code>getSession</code>, which I believe they are all run in server. I can get the value passed with cookie but not those passed with <code>request.locals.&lt;variable&gt;</code>:</p>
  <p><code>src/hooks.ts</code>:</p>
  <pre class="lang-js prettyprint-override"><code>import cookie from 'cookie'
  
  export async function handle({request, resolve}) {
    const cookies = cookie.parse(request.headers.cookie || '')
  
    request.locals.accessToken = cookies.accessToken
    request.locals.refreshToken = cookies.refreshToken
  
    const response = await resolve(request)
  
    const accessToken = `accessToken=${request.locals.accessToken || ''}; Path=/; Secure; HttpOnly;`
    const refreshToken = `refreshToken=${request.locals.refreshToken || ''}; Path=/; Secure; HttpOnly;`
  
    response.headers['set-cookie'] = [accessToken, refreshToken]
    
    return response
  }
  
  export async function getSession(request) {
      console.log('check request local', request.locals)
    return {
      accessToken: request.locals.accessToken,
      refreshToken: request.locals.refreshToken,
      user: request.locals.user
    }
  }
  </code></pre>
  <p>My endpoint:</p>
  <pre class="lang-js prettyprint-override"><code>export const post: RequestHandler&lt;Locals, FormData&gt; = async(req) =&gt; {
      const name = req.body.get(&quot;name&quot;)
      const password = req.body.get(&quot;password&quot;)
  
      if (!name || !password) {
          return {
              status: 400,
              body: {
                  message: &quot;Missing username or password&quot;
              }
          }
      }
      const { access_token, refresh_token } = await getAccessToken(name, password)
  
    req.locals.accessToken = access_token
    req.locals.refreshToken = refresh_token
  
      const user = await getUser(access_token)
  
      req.locals.user = user
    
    return {
      status: 302,
      headers: {
        location: '/lobby'
      }
    }
  }
  </code></pre>
  <p>Should I run <code>getUser</code> in <code>handle</code>, if I want to pass data with <code>request.locals</code> to <code>getSession</code>?</p>
  <p><strong>Edit</strong></p>
  <p>I am actually able to get the value of <code>request.locals.user</code> after <code>const response = await resolve(request)</code>, but not before <code>resolve</code>. Why is that?</p>