Skip to content

Commit

Permalink
docs: fix code error for API protection with node(express)
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaohanyu committed Dec 13, 2023
1 parent 3536964 commit 6af00c3
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ The request should contain an `Authorization` header with a `Bearer <access_toke
import { IncomingHttpHeaders } from 'http';

const extractBearerTokenFromHeaders = ({ authorization }: IncomingHttpHeaders) => {
const bearerTokenIdentifier = 'Bearer'

Check failure on line 16 in docs/docs/recipes/protect-your-api/fragments/_token_extract.mdx

View workflow job for this annotation

GitHub Actions / main-lint

Insert `;`

if (!authorization) {
throw new Error({ code: 'auth.authorization_header_missing', status: 401 });
}

if (!authorization.startsWith('Bearer')) {
if (!authorization.startsWith(bearerTokenIdentifier)) {
throw new Error({ code: 'auth.authorization_token_type_not_supported', status: 401 });
}

Expand Down
4 changes: 3 additions & 1 deletion docs/docs/recipes/protect-your-api/node.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ A authorized request should contain an `Authorization` header with `Bearer <acce
import { IncomingHttpHeaders } from 'http';

const extractBearerTokenFromHeaders = ({ authorization }: IncomingHttpHeaders) => {
const bearerTokenIdentifier = 'Bearer'

Check failure on line 25 in docs/docs/recipes/protect-your-api/node.mdx

View workflow job for this annotation

GitHub Actions / main-lint

Insert `;`

if (!authorization) {
throw new Error({ code: 'auth.authorization_header_missing', status: 401 });
}

if (!authorization.startsWith('Bearer')) {
if (!authorization.startsWith(bearerTokenIdentifier)) {
throw new Error({ code: 'auth.authorization_token_type_not_supported', status: 401 });
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ The request should contain an `Authorization` header with a `Bearer <access_toke
import { IncomingHttpHeaders } from 'http';

const extractBearerTokenFromHeaders = ({ authorization }: IncomingHttpHeaders) => {
const bearerTokenIdentifier = 'Bearer'

Check failure on line 16 in versioned_docs/version-1.x/docs/recipes/protect-your-api/fragments/_token_extract.mdx

View workflow job for this annotation

GitHub Actions / main-lint

Insert `;`

if (!authorization) {
throw new Error({ code: 'auth.authorization_header_missing', status: 401 });
}

if (!authorization.startsWith('Bearer')) {
if (!authorization.startsWith(bearerTokenIdentifier)) {
throw new Error({ code: 'auth.authorization_token_type_not_supported', status: 401 });
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ A authorized request should contain an `Authorization` header with `Bearer <acce
import { IncomingHttpHeaders } from 'http';

const extractBearerTokenFromHeaders = ({ authorization }: IncomingHttpHeaders) => {
const bearerTokenIdentifier = 'Bearer'

Check failure on line 25 in versioned_docs/version-1.x/docs/recipes/protect-your-api/node.mdx

View workflow job for this annotation

GitHub Actions / main-lint

Insert `;`

if (!authorization) {
throw new Error({ code: 'auth.authorization_header_missing', status: 401 });
}

if (!authorization.startsWith('Bearer')) {
if (!authorization.startsWith(bearerTokenIdentifier)) {
throw new Error({ code: 'auth.authorization_token_type_not_supported', status: 401 });
}

Expand Down

0 comments on commit 6af00c3

Please sign in to comment.