HonoH
Hono2y ago
Rubyae

Hono Oauth Provider with JWT issue

Hey everyone! I'm not sure if this is the right place for me to post about this but recently I wanted to try to use Hono and also saw there was a package for it @hoino/oauth-providers which I also wanted to try.

Now I noticed that in my main login.ts route where I use hono/jwt package then I'm getting errors inside my google.ts file where I use the googleAuth from @hono/oauth-providers/google. Currently I'm still using the basic stuff to figure out how things work and how I can use it so don't mind that.

This is my /routes/auth/login.ts file
import { Hono } from "hono";
import { sign } from 'hono/jwt'

const router = new Hono();

router.get('/', async (c) => {
    const payload = {
        sub: 'user123',
        role: 'admin',
        exp: Math.floor(Date.now() / 1000) + 60 * 5, // Token expires in 5 minutes
    }
    const secret = ''
    const token = await sign(payload, secret)
    return c.json({ token: token });
});

module.exports = router;

and this is my /routes/auth/google.ts file
import { Hono } from "hono";
import { googleAuth } from '@hono/oauth-providers/google'

const gAuth = googleAuth({
    client_id: '',
    client_secret: '',
    scope: ['openid', 'email', 'profile'],
});

const router = new Hono();

router.get('/', gAuth, (c) => {

    const token = c.get('token');
    const grantedScopes = c.get('granted-scopes');
    const user = c.get('user-google');

    return c.json({
        token,
        grantedScopes,
        user,
    });
});

module.exports = router;


and my vscode shows an error on the 3 const in google.ts:
No overload matches this call.
  Overload 1 of 2, '(key: "jwtPayload"): any', gave the following error.
    Argument of type '"user-google"' is not assignable to parameter of type '"jwtPayload"'.
  Overload 2 of 2, '(key: never): unknown', gave the following error.
    Argument of type 'string' is not assignable to parameter of type 'never'.


I'm not really sure why exactly this is happening and how to resolve it but I did notice that it comes from the hono/jwt usage which has the following in it's index.d.ts which is also weird cause the oauth-provider package has something similar too:
declare module '../../context' {
    interface ContextVariableMap {
        jwtPayload: any;
    }
}


not sure if this is a bug that I should report or why this is happening/how to resolve it, I'd appreciate any help on this! ^^
image.png
Was this page helpful?