adonisjs / ally

AdonisJS Social Authentication Provider
MIT License
158 stars 54 forks source link

node ace serve crash when using linkedin provider #153

Closed LoicOuth closed 1 month ago

LoicOuth commented 1 month ago

Package version

5.0.2

Describe the bug

When I add linkedin provider inside ally config my node ace server crash with following error :

/Users/loic/Documents/workspace/perso/ocj/start/kernel.ts:18
server.errorHandler(() => import('#core/exceptions/handler'))
       ^

TypeError: Cannot read properties of undefined (reading 'errorHandler')
    at <anonymous> (/Users/loic/Documents/workspace/perso/ocj/start/kernel.ts:18:8)

Node.js v22.6.0

Here my ally config :

import env from '#start/env'
import { defineConfig, services } from '@adonisjs/ally'

const allyConfig = defineConfig({
  google: services.google({
    clientId: env.get('GOOGLE_CLIENT_ID'),
    clientSecret: env.get('GOOGLE_CLIENT_SECRET'),
    callbackUrl: env.get('GOOGLE_CALLBACK_URL'),
    accessType: 'offline',
    display: 'page',
    scopes: ['userinfo.email', 'userinfo.profile'],
  }),
  linkedin: services.linkedin({
    clientId: env.get('LINKEDIN_CLIENT_ID'),
    clientSecret: env.get('LINKEDIN_CLIENT_SECRET'),
    callbackUrl: env.get('LINKEDIN_CALLBACK_URL'),
    // LinkedIn specific
    scopes: ['r_emailaddress', 'r_liteprofile'],
  }),
})

export default allyConfig

declare module '@adonisjs/ally/types' {
  interface SocialProviders extends InferSocialProviders<typeof allyConfig> {}
}

and my package.json

{
  "name": "ocj",
  "version": "1.0.0",
  "private": true,
  "type": "module",
  "license": "UNLICENSED",
  "scripts": {
    "start": "node bin/server.js",
    "build": "node ace build",
    "dev": "node ace serve --hmr",
    "test": "node ace test",
    "lint": "eslint .",
    "format": "prettier --write .",
    "typecheck": "tsc --noEmit"
  },
  "imports": {
    "#controllers/*": "./app/controllers/*.js",
    "#exceptions/*": "./app/exceptions/*.js",
    "#start/*": "./start/*.js",
    "#config/*": "./config/*.js",
    "#types/*": "./types/*.js",
    "#notifications/*": "./app/notifications/*.js",
    "#auth/*": "./app/auth/*.js",
    "#core/*": "./app/core/*.js",
    "#me/*": "./app/me/*.js",
    "#home/*": "./app/public/home/*.js",
    "#dashboard/*": "./app/admin/dashboard/*.js"
  },
  "devDependencies": {
    "@adonisjs/assembler": "^7.7.0",
    "@adonisjs/eslint-config": "^1.3.0",
    "@adonisjs/prettier-config": "^1.3.0",
    "@adonisjs/tsconfig": "^1.3.0",
    "@japa/assert": "^3.0.0",
    "@japa/plugin-adonisjs": "^3.0.1",
    "@japa/runner": "^3.1.4",
    "@swc/core": "^1.7.10",
    "@types/luxon": "^3.4.2",
    "@types/node": "^22.2.0",
    "@vitejs/plugin-vue": "^5.1.2",
    "autoprefixer": "^10.4.20",
    "eslint": "^9.9.0",
    "hot-hook": "^0.2.6",
    "pino-pretty": "^11.2.2",
    "prettier": "^3.3.3",
    "tailwindcss": "^3.4.9",
    "ts-node": "^10.9.2",
    "typescript": "^5.5.4",
    "unplugin-auto-import": "^0.18.2",
    "unplugin-vue-components": "^0.27.3",
    "vite": "^5.4.0"
  },
  "dependencies": {
    "@adonisjs/ally": "^5.0.2",
    "@adonisjs/auth": "^9.2.3",
    "@adonisjs/core": "^6.12.1",
    "@adonisjs/cors": "^2.2.1",
    "@adonisjs/inertia": "1.1.0",
    "@adonisjs/lucid": "^21.2.0",
    "@adonisjs/session": "^7.4.2",
    "@adonisjs/shield": "^8.1.1",
    "@adonisjs/static": "^1.1.1",
    "@adonisjs/transmit": "^1.0.2",
    "@adonisjs/transmit-client": "^1.0.0",
    "@adonisjs/vite": "^3.0.0",
    "@inertiajs/vue3": "^1.2.0",
    "@vinejs/vine": "^2.1.0",
    "@vue/server-renderer": "^3.4.37",
    "@vueuse/core": "^10.11.1",
    "class-variance-authority": "^0.7.0",
    "clsx": "^2.1.1",
    "edge.js": "^6.0.2",
    "lucide-vue-next": "^0.427.0",
    "luxon": "^3.5.0",
    "mysql2": "^3.11.0",
    "radix-vue": "^1.9.4",
    "reflect-metadata": "^0.2.2",
    "tailwind-merge": "^2.5.2",
    "tailwindcss-animate": "^1.0.7",
    "vaul-vue": "^0.2.0",
    "vue": "^3.4.37",
    "vue-i18n": "^9.13.1",
    "vue-sonner": "^1.1.4"
  },
  "hotHook": {
    "boundaries": [
      "./app/controllers/**/*.ts",
      "./app/middleware/*.ts"
    ]
  },
  "eslintConfig": {
    "extends": "@adonisjs/eslint-config/app"
  },
  "prettier": "@adonisjs/prettier-config"
}

Reproduction repo

No response

RomainLanz commented 1 month ago

Hey @LoicOuth! 👋🏻

This error is coming from Transmit and not Ally.

We have pushed a beta version of Transmit V2, which should fix it. May you install it using the @adonisjs/transmit@next tag and see how it goes?

The main changes are the way we can modify the routes defined by Transmit. You can remove the routeHandlerModifier from your configuration (and remove the import of middleware) and copy-paste this into your route file.

import transmit from '@adonisjs/transmit/services/main'

transmit.registerRoute(() => {
  // Your route's customization code here
})

Also, the method authorizeChannel was renamed authorize.

Let me know if it works for you. 👍🏻

LoicOuth commented 1 month ago

Hello @RomainLanz,

Thanks for your quick response. I upgraded the Transmit package, and it's working great now. I apologize for bringing up this issue here, but it only appeared when I added the LinkedIn provider to my Ally config.

Have a good day ✌️

RomainLanz commented 1 month ago

Great!

Since it is a beta version of the new Transmit package, could you please keep me updated if everything works fine?

You may have lost typings but this is going to be fixed for the final release.