Skip to content

Modern.js and Hono OAuth Middleware #7274

Answered by zllkjc
RuBAN-GT asked this question in Q&A
Discussion options

You must be logged in to vote

Thanks for your feedback, Using MiddlewareHandler, the UnstableMiddleware is deprecated.
https://modernjs.dev/zh/guides/advanced-features/web-server.html#middleware

You can try to code it like this:

import { defineServerConfig, type MiddlewareHandler } from '@modern-js/server-runtime';

const googleAuthHandler: MiddlewareHandler = googleAuth({
    client_id: Bun.env.GOOGLE_ID,
    client_secret: Bun.env.GOOGLE_SECRET,
    scope: ['openid', 'email', 'profile'],
});

const googleRouteHandler: MiddlewareHandler = (c) => {
  const token = c.get('token')
  const grantedScopes = c.get('granted-scopes')
  const user = c.get('user-google')

  return c.json({
    token,
    grantedScopes,
    user,

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@RuBAN-GT
Comment options

Answer selected by RuBAN-GT
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants