Skip to content

Commit

Permalink
docs(jsdoc): JWT Auth Middleware (#2709)
Browse files Browse the repository at this point in the history
* JSX Renderer Middleware

* add `[]`

---------

Co-authored-by: Yusuke Wada <[email protected]>
  • Loading branch information
goisaki and yusukebe committed May 24, 2024
1 parent cb2fbee commit 872fdbd
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
27 changes: 27 additions & 0 deletions deno_dist/middleware/jwt/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,33 @@ declare module '../../context.ts' {
}
}

/**
* JWT Auth middleware for Hono.
*
* @see {@link https://hono.dev/middleware/builtin/jwt}
*
* @param {object} options - The options for the JWT middleware.
* @param {string} options.secret - A value of your secret key.
* @param {string} [options.cookie] - If this value is set, then the value is retrieved from the cookie header using that value as a key, which is then validated as a token.
* @param {SignatureAlgorithm} [options.alg=HS256] - An algorithm type that is used for verifying. Available types are `HS256` | `HS384` | `HS512` | `RS256` | `RS384` | `RS512` | `PS256` | `PS384` | `PS512` | `ES256` | `ES384` | `ES512` | `EdDSA`.
* @returns {MiddlewareHandler} The middleware handler function.
*
* @example
* ```ts
* const app = new Hono()
*
* app.use(
* '/auth/*',
* jwt({
* secret: 'it-is-very-secret',
* })
* )
*
* app.get('/auth/page', (c) => {
* return c.text('You are authorized')
* })
* ```
*/
export const jwt = (options: {
secret: string
cookie?: string
Expand Down
27 changes: 27 additions & 0 deletions src/middleware/jwt/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,33 @@ declare module '../../context' {
}
}

/**
* JWT Auth middleware for Hono.
*
* @see {@link https://hono.dev/middleware/builtin/jwt}
*
* @param {object} options - The options for the JWT middleware.
* @param {string} [options.secret] - A value of your secret key.
* @param {string} [options.cookie] - If this value is set, then the value is retrieved from the cookie header using that value as a key, which is then validated as a token.
* @param {SignatureAlgorithm} [options.alg=HS256] - An algorithm type that is used for verifying. Available types are `HS256` | `HS384` | `HS512` | `RS256` | `RS384` | `RS512` | `PS256` | `PS384` | `PS512` | `ES256` | `ES384` | `ES512` | `EdDSA`.
* @returns {MiddlewareHandler} The middleware handler function.
*
* @example
* ```ts
* const app = new Hono()
*
* app.use(
* '/auth/*',
* jwt({
* secret: 'it-is-very-secret',
* })
* )
*
* app.get('/auth/page', (c) => {
* return c.text('You are authorized')
* })
* ```
*/
export const jwt = (options: {
secret: string
cookie?: string
Expand Down

0 comments on commit 872fdbd

Please sign in to comment.