Skip to content

Commit

Permalink
Prod (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
cermakjiri authored Oct 10, 2024
2 parents 950e93e + acdc4e2 commit 008b8d9
Show file tree
Hide file tree
Showing 17 changed files with 822 additions and 1,552 deletions.
675 changes: 675 additions & 0 deletions LICENSE.md

Large diffs are not rendered by default.

48 changes: 48 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,51 @@
# With WebAuthn

A repository with full stack WebAuthn API examples.

<div style="text-align:left">

## Examples

1. **[Passkeys with SimpleWebAuthn & Firebase](examples/simplewebauthn)**
- Creating (user registration), retrieving (user login), linking, removing of passkeys.
- Issuing a JWT token via Firebase Auth once user is authenticated.
- Passkes are stored in Firebase Firestore.
- Formatting and parsing of WebAuthn API request / responses done via SimpleWebAuthn library.

---

## Development

### Common Stack notes:

- The whole project is managed using tuborepo and yarn workspaces.
- All examples are in NextJS (React) framework.
- API calls are handled with React Tanstack query on client.
- API endpoints are build via NextJS API routes.
- Forms are built with react-hook-form and validated with zod schemas.
- Material UI with styled components as UI SDK.

### How to start the project locally?

1. Initialize package manager:
Make sure you're running Node v20. Then initialize a package manager (corepack) by calling:

```sh
corepack enable
corepack install
```

It finds `packageManager` field and install Yarn 4.

2. Install dependencies:

```sh
yarn install --immutable
```

3. Then continue with final steps for specific example:
- [Passkeys with SimpleWebAuthn & Firebase](examples/simplewebauthn/README.md)

## Have you a found a bug?

Please, open an [Github issue](https://github.com/cermakjiri/with-webauthn/issues/new/choose). Thank you. ❤️
19 changes: 19 additions & 0 deletions examples/simplewebauthn/.env.template.local
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Next.js
NEXT_TELEMETRY_DISABLED=1

NEXT_PUBLIC_CLIENT_ORIGIN=http://localhost:3000
# NEXT_PUBLIC_CLIENT_ORIGIN=https://14e5-2a07-b242-101a-9700-15d2-5b2c-c72c-ab56.ngrok-free.app

NEXT_PUBLIC_FIREBASE_API_KEY=""
NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN=""
NEXT_PUBLIC_FIREBASE_PROJECT_ID= ""
NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET=""
NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID=""
NEXT_PUBLIC_FIREBASE_APP_ID=""
NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID=""

# Sentry
NEXT_PUBLIC_DEV_SENTRY_DISABLED=true
# NEXT_PUBLIC_SENTRY_DSN=""
# SENTRY_ORG=""
# SENTRY_PROJECT=""
3 changes: 3 additions & 0 deletions examples/simplewebauthn/.env.template.server
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FIREBASE_PROJECT_ID=""
FIREBASE_PRIVATE_KEY=""
FIREBASE_CLIENT_EMAIL=""
33 changes: 33 additions & 0 deletions examples/simplewebauthn/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Passkeys with SimpleWebAuthn & Firebase

- Creating (user registration), retrieving (user login), linking, removing of passkeys.
- Issuing a JWT token via Firebase Auth once user is authenticated.
- Passkes are stored in Firebase Firestore.
- Formatting and parsing of WebAuthn API request / responses done via SimpleWebAuthn library.

## Development

### How to start it locally?

Assuming you've already finished [those steps in the main README](../../README.md), let's proceed:

1. Setup Firebase:

1. Create a new Firebase project

2. Copy `.env.template.local` to `.env.local`:

- Fill up all those `NEXT_PUBLIC_FIREBASE_` env. vars.

3. Copy `.env.template.server` to `.env.server`:

- Create a new private key in `Firebase > Project settings > Service accounts`.
- Fill up all those `Firebase_` env. vars.

4. Don't forget to add `localhost` as Authorized domain in Firebase:

- Firebase > Authentication > Settings > Authorised domains.

5. Create a Firebase firestore database

2. Run `yarn dev` and checkout `http://localhost:3000` URL.
2 changes: 1 addition & 1 deletion examples/simplewebauthn/next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { config } from 'dotenv';
// @ts-check
import ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';

// import './src/env/env.mjs';
import './src/env/env.mjs';

if (process.env.NODE_ENV === 'development') {
config({
Expand Down
2 changes: 1 addition & 1 deletion examples/simplewebauthn/src/env/env.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export const env = createEnv({
shared: {
NEXT_PUBLIC_CLIENT_ORIGIN: z.string().url(),
NEXT_PUBLIC_DEV_SENTRY_DISABLED: z.enum(['true', 'false']).optional(),
NEXT_PUBLIC_SENTRY_DSN: z.string(),
NEXT_PUBLIC_SENTRY_DSN: process.env.NODE_ENV === 'development' ? z.string().optional() : z.string(),
},

client: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const MainHeader = ({ pageTitle }: MainHeaderProps) => {
<Head>
<title>{`${pageTitle} | With WebAuthn`}</title>
</Head>
<PageHeader>With WebAuthn demos</PageHeader>
<PageHeader>With WebAuthn demo</PageHeader>
</>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const RegisterWithPasskey = () => {
schema={registerFormSchema}
defaultValues={{
// Some some random email to make it easier for demo users
email: 'some.[email protected]',
email: `user${Math.floor(Math.random() * 1e3)}@gmail.com`,
}}
onSubmit={registerPasskey}
>
Expand Down
7 changes: 1 addition & 6 deletions examples/simplewebauthn/src/server/env/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,9 @@ import dotenv from 'dotenv';
import { z } from 'zod';

if (process.env.NODE_ENV !== 'production') {
const envs = dotenv.config({
dotenv.config({
path: '.env.server',
processEnv: {},
});

if (envs.error) {
throw new Error(envs.error.message);
}
}

export const env = z
Expand Down
15 changes: 14 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "with-webauthn",
"description": "A project with full-stack WebAuthn API examples.",
"packageManager": "[email protected]",
"private": true,
"type": "commonjs",
Expand Down Expand Up @@ -32,5 +33,17 @@
"husky": "9.1.6",
"turbo": "2.1.3"
},
"prettier": "@tooling/prettier/config"
"prettier": "@tooling/prettier/config",
"license": "GPL-3.0-only",
"author": {
"name": "Jiří Čermák"
},
"repository": {
"type": "git",
"url": "https://github.com/cermakjiri/with-webauthn"
},
"homepage": "https://with-webauthn.dev",
"bugs": {
"url": "https://github.com/cermakjiri/with-webauthn/issues"
}
}
18 changes: 0 additions & 18 deletions tooling/lokse/bin/cli.js

This file was deleted.

17 changes: 0 additions & 17 deletions tooling/lokse/config/index.js

This file was deleted.

17 changes: 0 additions & 17 deletions tooling/lokse/package.json

This file was deleted.

93 changes: 0 additions & 93 deletions tooling/lokse/scripts/transformTranslations.js

This file was deleted.

6 changes: 0 additions & 6 deletions tooling/lokse/tsconfig.json

This file was deleted.

Loading

0 comments on commit 008b8d9

Please sign in to comment.