OrJDev / solid-auth

SolidStart Adapter For AuthJS
17 stars 1 forks source link

Github provider sign in error #2

Closed Pumkko closed 1 year ago

Pumkko commented 1 year ago

Hi !

Running the default template with github i encountered the following issues :

[auth][cause]: TypeError: Cannot read properties of undefined (reading 'id')
    at Object.session (/src/server/auth.ts:11:32)
    at Module.session (file:///C:/Poketext/tailwind-solid-auth/node_modules/@auth/core/lib/routes/session.js:32:52)
    at async AuthInternal (file:///C:/Poketext/tailwind-solid-auth/node_modules/@auth/core/lib/index.js:28:33)
    at async Proxy.Auth (file:///C:/Poketext/tailwind-solid-auth/node_modules/@auth/core/index.js:100:30)
    at async eval (/node_modules/@solid-auth/base/index.js:25:16)
    at async Object.GET [as handler] (/node_modules/@solid-auth/base/index.js:37:20)
    at async eval (/node_modules/solid-start/api/middleware.ts:23:16)
    at async eval (/node_modules/solid-start/entry-server/StartServer.tsx:45:12)
    at async devFetch (file:///C:/Poketext/tailwind-solid-auth/node_modules/solid-start/dev/server.js:46:12)
    at async startHandler (file:///C:/Poketext/tailwind-solid-auth/node_modules/solid-start/dev/server.js:115:20)

Signing in works when i remove comment out the following code in server/auth.js

export const authOptions: SolidAuthConfig = {
  callbacks: {
    session({ session, user }) {
      /*if (session.user) {
        session.user.id = user.id;
      }*/
      return session;
    },
  },
  providers: [
    Github({
      clientId: serverEnv.GITHUB_ID,
      clientSecret: serverEnv.GITHUB_SECRET,
    }),
  ],
  debug: true,
};

With that change, Signing in works but it seems that i have a rerendering issue. After a successfull sign in the app does not display the correct information. image

In the image does not load correctly, the app shows : "Logged in as" and then nothing. Hiding Chrome and reopening it "fixes" the issue.

Here are my dependencies in my package.json

    "@solidjs/meta": "^0.28.2",
    "@solidjs/router": "^0.8.2",
    "solid-js": "^1.7.3",
    "solid-start": "^0.2.26",
    "undici": "5.20.0",
    "zod": "^3.20.6",
    "@auth/core": "^0.5.1",
    "@solid-auth/base": "^1.0.0"
OrJDev commented 1 year ago

There's this weird hydration issue with solidstart, there is an issue open for that - https://github.com/solidjs/solid-start/issues/830

What i recommend doing is fetching the session from the server directly for now (if you choose pRPC with create jd app it already does it for you)

Pumkko commented 1 year ago

Works perfectly thank you ! I still had the error about the user id though

[auth][cause]: TypeError: Cannot read properties of undefined (reading 'id')
    at Object.session (/src/server/auth.ts:11:32)
    at Module.session (file:///C:/Poketext/tailwind-solid-auth/node_modules/@auth/core/lib/routes/session.js:32:52)
    at async AuthInternal (file:///C:/Poketext/tailwind-solid-auth/node_modules/@auth/core/lib/index.js:28:33)
    at async Proxy.Auth (file:///C:/Poketext/tailwind-solid-auth/node_modules/@auth/core/index.js:100:30)
    at async eval (/node_modules/@solid-auth/base/index.js:25:16)
    at async Object.GET [as handler] (/node_modules/@solid-auth/base/index.js:37:20)
    at async eval (/node_modules/solid-start/api/middleware.ts:23:16)
    at async eval (/node_modules/solid-start/entry-server/StartServer.tsx:45:12)
    at async devFetch (file:///C:/Poketext/tailwind-solid-auth/node_modules/solid-start/dev/server.js:46:12)
    at async startHandler (file:///C:/Poketext/tailwind-solid-auth/node_modules/solid-start/dev/server.js:115:20)

It seems to work fine however without the callback code in auth.ts

OrJDev commented 1 year ago

Hey there this was fixed in https://github.com/OrJDev/solid-auth/commit/b20192450411df4688b3dcb873ab5b376aa74df8 could you try it out and lmk if you now get the correct data rendered?

using the createSession hook.

OrJDev commented 1 year ago

https://github.com/OrJDev/create-jd-app/releases/tag/v0.2.7

If you want to you can also create a new app with everything new configured

Pumkko commented 1 year ago

Works perfectly ! Thanks !