Skip to content

Commit

Permalink
Merge pull request #5 from lahirumaramba/lm-fix-npm
Browse files Browse the repository at this point in the history
fix: Remove deno-shims from node module
  • Loading branch information
lahirumaramba committed Jan 29, 2023
2 parents 93557e7 + fa1cf27 commit 00bed49
Show file tree
Hide file tree
Showing 23 changed files with 6,352 additions and 11 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# edge_token_verifier

Experimental token verifier that works on the Edge.

Hello there! This is an early stage experimental Deno module to verify tokens on
edge runtime. We are also experimenting with
[`dnt`](https://github.com/denoland/dnt) to create the the Node.js compatible
module.

We are currently testing the module on different edge runtimes. The current
releases are only for testing purposes.
4 changes: 0 additions & 4 deletions deno.lock
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,6 @@
"https://deno.land/std@0.171.0/path/posix.ts": "2ecc259e6f34013889b7638ff90339a82d8178f629155761ce6001e41af55a43",
"https://deno.land/std@0.171.0/path/separator.ts": "0fb679739d0d1d7bf45b68dacfb4ec7563597a902edbaf3c59b50d5bcadd93b1",
"https://deno.land/std@0.171.0/path/win32.ts": "99170a0eb0e2b1ce41499c1e86bb55320cb6606299ad947f57ee0a291cdb93d5",
"https://deno.land/std@0.173.0/fmt/colors.ts": "938c5d44d889fb82eff6c358bea8baa7e85950a16c9f6dae3ec3a7a729164471",
"https://deno.land/std@0.173.0/testing/_diff.ts": "1a3c044aedf77647d6cac86b798c6417603361b66b54c53331b312caeb447aea",
"https://deno.land/std@0.173.0/testing/_format.ts": "a69126e8a469009adf4cf2a50af889aca364c349797e63174884a52ff75cf4c7",
"https://deno.land/std@0.173.0/testing/asserts.ts": "984ab0bfb3faeed92ffaa3a6b06536c66811185328c5dd146257c702c41b01ab",
"https://deno.land/std@0.175.0/fmt/colors.ts": "938c5d44d889fb82eff6c358bea8baa7e85950a16c9f6dae3ec3a7a729164471",
"https://deno.land/std@0.175.0/testing/_diff.ts": "1a3c044aedf77647d6cac86b798c6417603361b66b54c53331b312caeb447aea",
"https://deno.land/std@0.175.0/testing/_format.ts": "a69126e8a469009adf4cf2a50af889aca364c349797e63174884a52ff75cf4c7",
Expand Down
3 changes: 3 additions & 0 deletions examples/edge-token-vc/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "next/core-web-vitals"
}
36 changes: 36 additions & 0 deletions examples/edge-token-vc/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.pnpm-debug.log*

# local env files
.env*.local

# vercel
.vercel

# typescript
*.tsbuildinfo
next-env.d.ts
54 changes: 54 additions & 0 deletions examples/edge-token-vc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
This is a [Next.js](https://nextjs.org/) project bootstrapped with
[`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).

## Getting Started

First, run the development server:

```bash
npm run dev
# or
yarn dev
# or
pnpm dev
```

Open [http://localhost:3000](http://localhost:3000) with your browser to see the
result.

You can start editing the page by modifying `pages/index.tsx`. The page
auto-updates as you edit the file.

[API routes](https://nextjs.org/docs/api-routes/introduction) can be accessed on
[http://localhost:3000/api/hello](http://localhost:3000/api/hello). This
endpoint can be edited in `pages/api/hello.ts`.

The `pages/api` directory is mapped to `/api/*`. Files in this directory are
treated as [API routes](https://nextjs.org/docs/api-routes/introduction) instead
of React pages.

This project uses
[`next/font`](https://nextjs.org/docs/basic-features/font-optimization) to
automatically optimize and load Inter, a custom Google Font.

## Learn More

To learn more about Next.js, take a look at the following resources:

- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js
features and API.
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.

You can check out
[the Next.js GitHub repository](https://github.com/vercel/next.js/) - your
feedback and contributions are welcome!

## Deploy on Vercel

The easiest way to deploy your Next.js app is to use the
[Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme)
from the creators of Next.js.

Check out our
[Next.js deployment documentation](https://nextjs.org/docs/deployment) for more
details.
32 changes: 32 additions & 0 deletions examples/edge-token-vc/middleware.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// middleware.ts
import { NextResponse } from 'next/server';
import type { NextRequest } from 'next/server';
import { AppCheckTokenVerifier } from '@lahirumaramba/edge-token-verifier';

export async function middleware(request: NextRequest) {
const verifyAppCheckToken = async (appCheckToken: string) => {
if (!appCheckToken) {
return null;
}
const tokenVerifier = new AppCheckTokenVerifier();
try {
return await tokenVerifier.verify(appCheckToken, 'admin-sdk-8b7ba');
} catch (_err) {
return null;
}
};
const appCheckToken = request.headers.get('X-Firebase-AppCheck');
const appCheckClaims = await verifyAppCheckToken(appCheckToken);

if (!appCheckClaims) {
return NextResponse.json(
{ message: 'Unauthorized access. Invalid App Check token.' },
{ status: 401, headers: { 'content-type': 'application/json' } },
);
}
return NextResponse.next();
}

export const config = {
matcher: '/api/hello/:path*',
};
6 changes: 6 additions & 0 deletions examples/edge-token-vc/next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true,
};

module.exports = nextConfig;

0 comments on commit 00bed49

Please sign in to comment.