Compare commits
76 Commits
jazz-react
...
cojson-sto
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0acdcf5f5f | ||
|
|
dafcce5ecd | ||
|
|
c93536f795 | ||
|
|
7bad34f2f5 | ||
|
|
91e0c09f33 | ||
|
|
e2d6ba3922 | ||
|
|
ba460c7b70 | ||
|
|
fc9f7c9199 | ||
|
|
2fcea1e91b | ||
|
|
191ae380c8 | ||
|
|
eef1a5d994 | ||
|
|
daee7b900d | ||
|
|
9afcd38e3b | ||
|
|
477ff0284a | ||
|
|
85604ec4c5 | ||
|
|
1c641ad03d | ||
|
|
87cfca41f0 | ||
|
|
2783f8c308 | ||
|
|
de783063e2 | ||
|
|
9681691701 | ||
|
|
6c7ae1faee | ||
|
|
12e9837858 | ||
|
|
422dbc4222 | ||
|
|
e7ccb2c054 | ||
|
|
2f7046002d | ||
|
|
20c1588249 | ||
|
|
f3d3d4dc5d | ||
|
|
3135d711d4 | ||
|
|
14ad9622ea | ||
|
|
0fee2aa21b | ||
|
|
1e6581cd68 | ||
|
|
aaacaf0130 | ||
|
|
7dcca057e7 | ||
|
|
63570520a3 | ||
|
|
aeed9595ae | ||
|
|
6755e28d0f | ||
|
|
8e5ff13115 | ||
|
|
23521e6468 | ||
|
|
1627eb7652 | ||
|
|
ff846d9095 | ||
|
|
8d7d62d64f | ||
|
|
65a8227b2b | ||
|
|
a846e0730e | ||
|
|
e9c0e65170 | ||
|
|
14636606bd | ||
|
|
5118ff6585 | ||
|
|
51a0f86b99 | ||
|
|
fa61ab4eb5 | ||
|
|
d4cdd43cf7 | ||
|
|
c5d5fb25f7 | ||
|
|
38f2276fdd | ||
|
|
b92bfce041 | ||
|
|
e3fd7bf6e3 | ||
|
|
7526e444d6 | ||
|
|
28522bd062 | ||
|
|
824be82f94 | ||
|
|
8a9ef8ac78 | ||
|
|
5fb2f959f1 | ||
|
|
7a900d43f3 | ||
|
|
c8624d56d2 | ||
|
|
8ed7c3947d | ||
|
|
ec0e61a442 | ||
|
|
824d417d4e | ||
|
|
9f1ce81e09 | ||
|
|
48b32b6a72 | ||
|
|
03fec5f1b3 | ||
|
|
cdd7ac98cc | ||
|
|
8218a272ee | ||
|
|
25d146ead8 | ||
|
|
3f4d493286 | ||
|
|
d476b06d0e | ||
|
|
22baf1f547 | ||
|
|
d6ec873b1e | ||
|
|
160b30406b | ||
|
|
3e473eff50 | ||
|
|
a9cf6da27a |
10
.github/ISSUE_TEMPLATE/docs-request.md
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
---
|
||||
name: Docs request
|
||||
about: Allow people to quickly report issues & improvements for the docs
|
||||
title: 'Docs: '
|
||||
labels: docs, requested
|
||||
assignees: bensleveritt
|
||||
|
||||
---
|
||||
|
||||
|
||||
2
.github/workflows/playwright.yml
vendored
@@ -13,7 +13,7 @@ jobs:
|
||||
continue-on-error: true
|
||||
strategy:
|
||||
matrix:
|
||||
project: ["tests/e2e", "examples/chat", "examples/clerk", "examples/file-share-svelte", "examples/form", "examples/music-player", "examples/pets", "starters/react-passkey-auth"]
|
||||
project: ["tests/e2e", "examples/chat", "examples/clerk", "examples/betterauth", "examples/file-share-svelte", "examples/form", "examples/music-player", "examples/pets", "starters/react-passkey-auth"]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
1
examples/betterauth/.env
Normal file
@@ -0,0 +1 @@
|
||||
BETTER_AUTH_SECRET="TEST_SECRET"
|
||||
47
examples/betterauth/.gitignore
vendored
Normal file
@@ -0,0 +1,47 @@
|
||||
/test-results/
|
||||
/playwright-report/
|
||||
/blob-report/
|
||||
/playwright/.cache/
|
||||
sqlite.db
|
||||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
||||
|
||||
# dependencies
|
||||
/node_modules
|
||||
/.pnp
|
||||
.pnp.*
|
||||
.yarn/*
|
||||
!.yarn/patches
|
||||
!.yarn/plugins
|
||||
!.yarn/releases
|
||||
!.yarn/versions
|
||||
|
||||
# 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*
|
||||
|
||||
# env files (can opt-in for committing if needed)
|
||||
.env*
|
||||
!.env
|
||||
|
||||
# vercel
|
||||
.vercel
|
||||
|
||||
# typescript
|
||||
*.tsbuildinfo
|
||||
next-env.d.ts
|
||||
13
examples/betterauth/CHANGELOG.md
Normal file
@@ -0,0 +1,13 @@
|
||||
# betterauth
|
||||
|
||||
## 0.1.1
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [8e5ff13]
|
||||
- jazz-inspector@0.13.29
|
||||
- jazz-betterauth-server-plugin@0.0.1
|
||||
- jazz-react@0.13.29
|
||||
- jazz-react-auth-betterauth@0.0.1
|
||||
- jazz-tools@0.13.29
|
||||
- jazz-betterauth-client-plugin@0.0.1
|
||||
49
examples/betterauth/README.md
Normal file
@@ -0,0 +1,49 @@
|
||||
# Better Auth Integration Example
|
||||
|
||||
This example demonstrates using Jazz with Better Auth and Next.js.
|
||||
|
||||
## Getting started
|
||||
|
||||
To run this example, you may either:
|
||||
* Clone the Jazz monorepo and run this example from within.
|
||||
* Create a new Jazz project using this example as a template, and run that new project.
|
||||
|
||||
### Setting environment variables
|
||||
- `NEXT_PUBLIC_AUTH_BASE_URL`: A URL to a Better Auth server. If undefined, the example will self-host a Better Auth server.
|
||||
- `BETTER_AUTH_SECRET`: The encryption secret used by the self-hosted Better Auth server (required only if `NEXT_PUBLIC_AUTH_BASE_URL` is undefined)
|
||||
- `GITHUB_CLIENT_ID`: The client ID for the GitHub OAuth provider used by the self-hosted Better Auth server (required only if `NEXT_PUBLIC_AUTH_BASE_URL` is undefined)
|
||||
- `GITHUB_CLIENT_SECRET`: The client secret for the GitHub OAuth provider used by the self-hosted Better Auth server (required only if `NEXT_PUBLIC_AUTH_BASE_URL` is undefined)
|
||||
|
||||
### Using this example as a template
|
||||
|
||||
1. Create a new Jazz project, and use this example as a template.
|
||||
```sh
|
||||
npx create-jazz-app@latest betterauth-app --example betterauth
|
||||
```
|
||||
2. Navigate to the new project and start the development server.
|
||||
```sh
|
||||
cd betterauth-app
|
||||
pnpm install
|
||||
pnpm dev
|
||||
```
|
||||
|
||||
### Using the monorepo
|
||||
|
||||
This requires `pnpm` to be installed; see [https://pnpm.io/installation](https://pnpm.io/installation).
|
||||
|
||||
1. Clone the `jazz` repository.
|
||||
```sh
|
||||
git clone https://github.com/garden-co/jazz.git
|
||||
```
|
||||
2. Install dependencies.
|
||||
```sh
|
||||
cd jazz
|
||||
pnpm install
|
||||
```
|
||||
3. Navigate to the example and start the development server.
|
||||
```sh
|
||||
cd examples/betterauth
|
||||
pnpm dev
|
||||
```
|
||||
|
||||
The example should be running at [http://localhost:3000](http://localhost:3000) by default.
|
||||
7
examples/betterauth/next.config.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import type { NextConfig } from "next";
|
||||
|
||||
const nextConfig: NextConfig = {
|
||||
/* config options here */
|
||||
};
|
||||
|
||||
export default nextConfig;
|
||||
43
examples/betterauth/package.json
Normal file
@@ -0,0 +1,43 @@
|
||||
{
|
||||
"name": "betterauth",
|
||||
"version": "0.1.1",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "next dev --turbopack",
|
||||
"build": "next build",
|
||||
"start": "next start",
|
||||
"lint": "next lint",
|
||||
"format-and-lint": "biome check .",
|
||||
"format-and-lint:fix": "biome check . --write",
|
||||
"test:e2e": "playwright test",
|
||||
"test:e2e:ui": "playwright test --ui",
|
||||
"email": "email dev --dir src/components/emails"
|
||||
},
|
||||
"dependencies": {
|
||||
"@react-email/components": "^0.0.38",
|
||||
"better-auth": "^1.2.4",
|
||||
"better-sqlite3": "^11.9.1",
|
||||
"jazz-betterauth-server-plugin": "workspace:*",
|
||||
"jazz-betterauth-client-plugin": "workspace:*",
|
||||
"jazz-inspector": "workspace:*",
|
||||
"jazz-react": "workspace:*",
|
||||
"jazz-react-auth-betterauth": "workspace:*",
|
||||
"jazz-tools": "workspace:*",
|
||||
"next": "15.3.1",
|
||||
"react": "^18.0.0",
|
||||
"react-dom": "^18.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@biomejs/biome": "1.9.4",
|
||||
"@playwright/test": "^1.50.1",
|
||||
"@tailwindcss/postcss": "^4",
|
||||
"@types/better-sqlite3": "^7.6.12",
|
||||
"@types/node": "^20",
|
||||
"@types/react": "^18",
|
||||
"@types/react-dom": "^18",
|
||||
"react-email": "^4.0.11",
|
||||
"tailwindcss": "^4",
|
||||
"typescript": "^5"
|
||||
}
|
||||
}
|
||||
53
examples/betterauth/playwright.config.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
import { defineConfig, devices } from "@playwright/test";
|
||||
import isCI from "is-ci";
|
||||
|
||||
/**
|
||||
* Read environment variables from file.
|
||||
* https://github.com/motdotla/dotenv
|
||||
*/
|
||||
// import dotenv from 'dotenv';
|
||||
// dotenv.config({ path: path.resolve(__dirname, '.env') });
|
||||
|
||||
/**
|
||||
* See https://playwright.dev/docs/test-configuration.
|
||||
*/
|
||||
export default defineConfig({
|
||||
testDir: "./tests",
|
||||
/* Run tests in files in parallel */
|
||||
fullyParallel: true,
|
||||
/* Fail the build on CI if you accidentally left test.only in the source code. */
|
||||
forbidOnly: isCI,
|
||||
/* Retry on CI only */
|
||||
retries: isCI ? 2 : 0,
|
||||
/* Opt out of parallel tests on CI. */
|
||||
workers: isCI ? 1 : undefined,
|
||||
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
|
||||
reporter: "html",
|
||||
|
||||
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
|
||||
use: {
|
||||
/* Base URL to use in actions like `await page.goto('/')`. */
|
||||
baseURL: "http://localhost:3000/",
|
||||
|
||||
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
|
||||
trace: "on-first-retry",
|
||||
permissions: ["clipboard-read", "clipboard-write"],
|
||||
},
|
||||
|
||||
/* Configure projects for major browsers */
|
||||
projects: [
|
||||
{
|
||||
name: "chromium",
|
||||
use: { ...devices["Desktop Chrome"] },
|
||||
},
|
||||
],
|
||||
|
||||
/* Run your local dev server before starting the tests */
|
||||
webServer: [
|
||||
{
|
||||
command: "pnpm dev",
|
||||
url: "http://localhost:3000/",
|
||||
reuseExistingServer: !isCI,
|
||||
},
|
||||
],
|
||||
});
|
||||
5
examples/betterauth/postcss.config.mjs
Normal file
@@ -0,0 +1,5 @@
|
||||
const config = {
|
||||
plugins: ["@tailwindcss/postcss"],
|
||||
};
|
||||
|
||||
export default config;
|
||||
1
examples/betterauth/public/file.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg fill="none" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg"><path d="M14.5 13.5V5.41a1 1 0 0 0-.3-.7L9.8.29A1 1 0 0 0 9.08 0H1.5v13.5A2.5 2.5 0 0 0 4 16h8a2.5 2.5 0 0 0 2.5-2.5m-1.5 0v-7H8v-5H3v12a1 1 0 0 0 1 1h8a1 1 0 0 0 1-1M9.5 5V2.12L12.38 5zM5.13 5h-.62v1.25h2.12V5zm-.62 3h7.12v1.25H4.5zm.62 3h-.62v1.25h7.12V11z" clip-rule="evenodd" fill="#666" fill-rule="evenodd"/></svg>
|
||||
|
After Width: | Height: | Size: 391 B |
1
examples/betterauth/public/globe.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg fill="none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><g clip-path="url(#a)"><path fill-rule="evenodd" clip-rule="evenodd" d="M10.27 14.1a6.5 6.5 0 0 0 3.67-3.45q-1.24.21-2.7.34-.31 1.83-.97 3.1M8 16A8 8 0 1 0 8 0a8 8 0 0 0 0 16m.48-1.52a7 7 0 0 1-.96 0H7.5a4 4 0 0 1-.84-1.32q-.38-.89-.63-2.08a40 40 0 0 0 3.92 0q-.25 1.2-.63 2.08a4 4 0 0 1-.84 1.31zm2.94-4.76q1.66-.15 2.95-.43a7 7 0 0 0 0-2.58q-1.3-.27-2.95-.43a18 18 0 0 1 0 3.44m-1.27-3.54a17 17 0 0 1 0 3.64 39 39 0 0 1-4.3 0 17 17 0 0 1 0-3.64 39 39 0 0 1 4.3 0m1.1-1.17q1.45.13 2.69.34a6.5 6.5 0 0 0-3.67-3.44q.65 1.26.98 3.1M8.48 1.5l.01.02q.41.37.84 1.31.38.89.63 2.08a40 40 0 0 0-3.92 0q.25-1.2.63-2.08a4 4 0 0 1 .85-1.32 7 7 0 0 1 .96 0m-2.75.4a6.5 6.5 0 0 0-3.67 3.44 29 29 0 0 1 2.7-.34q.31-1.83.97-3.1M4.58 6.28q-1.66.16-2.95.43a7 7 0 0 0 0 2.58q1.3.27 2.95.43a18 18 0 0 1 0-3.44m.17 4.71q-1.45-.12-2.69-.34a6.5 6.5 0 0 0 3.67 3.44q-.65-1.27-.98-3.1" fill="#666"/></g><defs><clipPath id="a"><path fill="#fff" d="M0 0h16v16H0z"/></clipPath></defs></svg>
|
||||
|
After Width: | Height: | Size: 1.0 KiB |
21
examples/betterauth/public/jazz-logo.svg
Normal file
@@ -0,0 +1,21 @@
|
||||
<svg
|
||||
viewBox="0 0 386 146"
|
||||
fill="none"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
>
|
||||
<path id="text"
|
||||
d="M176.725 33.865H188.275V22.7H176.725V33.865ZM164.9 129.4H172.875C182.72 129.4 188.275 123.9 188.275 114.22V43.6H176.725V109.545C176.725 115.65 173.975 118.51 167.925 118.51H164.9V129.4ZM245.298 53.28C241.613 45.47 233.363 41.95 222.748 41.95C208.998 41.95 200.748 48.44 197.888 58.615L208.613 61.915C210.648 55.315 216.368 52.565 222.638 52.565C231.933 52.565 235.673 56.415 236.058 64.61C226.433 65.93 216.643 67.195 209.768 69.23C200.583 72.145 195.743 77.865 195.743 86.83C195.743 96.51 202.673 104.65 215.818 104.65C225.443 104.65 232.318 101.35 237.213 94.365V103H247.388V66.425C247.388 61.475 247.168 57.185 245.298 53.28ZM217.853 95.245C210.483 95.245 207.128 91.34 207.128 86.72C207.128 82.045 210.593 79.515 215.323 77.92C220.328 76.435 226.983 75.5 235.948 74.18C235.893 76.93 235.673 80.725 234.738 83.475C233.418 89.25 227.643 95.245 217.853 95.245ZM251.22 103H301.545V92.715H269.535L303.195 45.47V43.6H254.3V53.885H284.935L251.22 101.185V103ZM304.815 103H355.14V92.715H323.13L356.79 45.47V43.6H307.895V53.885H338.53L304.815 101.185V103Z"
|
||||
/>
|
||||
<style>
|
||||
path#text { fill: #000 }
|
||||
@media (prefers-color-scheme: dark) {
|
||||
path#text { fill: #fff }
|
||||
}
|
||||
</style>
|
||||
<path
|
||||
fillRule="evenodd"
|
||||
clipRule="evenodd"
|
||||
d="M136.179 44.8277C136.179 44.8277 136.179 44.8277 136.179 44.8276V21.168C117.931 28.5527 97.9854 32.6192 77.0897 32.6192C65.1466 32.6192 53.5138 31.2908 42.331 28.7737V51.4076C42.331 51.4076 42.331 51.4076 42.331 51.4076V81.1508C41.2955 80.4385 40.1568 79.8458 38.9405 79.3915C36.1732 78.358 33.128 78.0876 30.1902 78.6145C27.2524 79.1414 24.5539 80.4419 22.4358 82.3516C20.3178 84.2613 18.8754 86.6944 18.291 89.3433C17.7066 91.9921 18.0066 94.7377 19.1528 97.2329C20.2991 99.728 22.2403 101.861 24.7308 103.361C27.2214 104.862 30.1495 105.662 33.1448 105.662H33.1455C33.6061 105.662 33.8365 105.662 34.0314 105.659C44.5583 105.449 53.042 96.9656 53.2513 86.4386C53.2534 86.3306 53.2544 86.2116 53.2548 86.0486H53.2552V85.7149L53.2552 85.5521V82.0762L53.2552 53.1993C61.0533 54.2324 69.0092 54.7656 77.0897 54.7656C77.6696 54.7656 78.2489 54.7629 78.8276 54.7574V110.696C77.792 109.983 76.6533 109.391 75.437 108.936C72.6697 107.903 69.6246 107.632 66.6867 108.159C63.7489 108.686 61.0504 109.987 58.9323 111.896C56.8143 113.806 55.3719 116.239 54.7875 118.888C54.2032 121.537 54.5031 124.283 55.6494 126.778C56.7956 129.273 58.7368 131.405 61.2273 132.906C63.7179 134.406 66.646 135.207 69.6414 135.207C70.1024 135.207 70.3329 135.207 70.5279 135.203C81.0548 134.994 89.5385 126.51 89.7478 115.983C89.7517 115.788 89.7517 115.558 89.7517 115.097V111.621L89.7517 54.3266C101.962 53.4768 113.837 51.4075 125.255 48.2397V80.9017C124.219 80.1894 123.081 79.5966 121.864 79.1424C119.097 78.1089 116.052 77.8384 113.114 78.3653C110.176 78.8922 107.478 80.1927 105.36 82.1025C103.242 84.0122 101.799 86.4453 101.215 89.0941C100.631 91.743 100.931 94.4886 102.077 96.9837C103.223 99.4789 105.164 101.612 107.655 103.112C110.145 104.612 113.073 105.413 116.069 105.413C116.53 105.413 116.76 105.413 116.955 105.409C127.482 105.2 135.966 96.7164 136.175 86.1895C136.179 85.9945 136.179 85.764 136.179 85.3029V81.8271L136.179 44.8277Z"
|
||||
fill="#146AFF"
|
||||
/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 3.3 KiB |
12
examples/betterauth/public/jazz.svg
Normal file
@@ -0,0 +1,12 @@
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
viewBox="0 0 125 125"
|
||||
fill="none"
|
||||
>
|
||||
<path
|
||||
fillRule="evenodd"
|
||||
clipRule="evenodd"
|
||||
d="M118.179 29.6597V6C99.931 13.3847 79.9854 17.4512 59.0897 17.4512C47.1466 17.4512 35.5138 16.1228 24.331 13.6057V36.2396V65.9828C23.2955 65.2705 22.1568 64.6778 20.9405 64.2235C18.1732 63.19 15.128 62.9196 12.1902 63.4465C9.25242 63.9734 6.55392 65.2739 4.43582 67.1836C2.31782 69.0933 0.875416 71.5264 0.291016 74.1753C-0.293384 76.8241 0.00661504 79.5697 1.15281 82.0649C2.29911 84.56 4.24032 86.693 6.73082 88.193C9.22142 89.694 12.1495 90.494 15.1448 90.494C15.6054 90.494 15.8365 90.494 16.0314 90.491C26.5583 90.281 35.042 81.7976 35.2513 71.2706C35.2534 71.1626 35.2544 71.0436 35.2548 70.8806L35.2552 70.5469V70.3841V66.9082V38.0313C43.0533 39.0644 51.0092 39.5976 59.0897 39.5976C59.6696 39.5976 60.2489 39.5949 60.8276 39.5894V95.528C59.792 94.815 58.6533 94.223 57.437 93.768C54.6697 92.735 51.6246 92.464 48.6867 92.991C45.7489 93.518 43.0504 94.819 40.9323 96.728C38.8143 98.638 37.3719 101.071 36.7875 103.72C36.2032 106.369 36.5031 109.115 37.6494 111.61C38.7956 114.105 40.7368 116.237 43.2273 117.738C45.7179 119.238 48.646 120.039 51.6414 120.039C52.1024 120.039 52.3329 120.039 52.5279 120.035C63.0548 119.826 71.5385 111.342 71.7478 100.815C71.7517 100.62 71.7517 100.39 71.7517 99.929V96.453V39.1586C83.962 38.3088 95.837 36.2395 107.255 33.0717V65.7337C106.219 65.0214 105.081 64.4286 103.864 63.9744C101.097 62.9409 98.052 62.6704 95.114 63.1973C92.176 63.7242 89.478 65.0247 87.36 66.9345C85.242 68.8442 83.799 71.2773 83.215 73.9261C82.631 76.575 82.931 79.3206 84.077 81.8157C85.223 84.3109 87.164 86.444 89.655 87.944C92.145 89.444 95.073 90.245 98.069 90.245C98.53 90.245 98.76 90.245 98.955 90.241C109.482 90.032 117.966 81.5484 118.175 71.0215C118.179 70.8265 118.179 70.596 118.179 70.1349V66.6591V29.6597Z"
|
||||
fill="#146AFF"
|
||||
/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.9 KiB |
1
examples/betterauth/public/link.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="#666" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-link-icon lucide-link"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"/><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"/></svg>
|
||||
|
After Width: | Height: | Size: 344 B |
1
examples/betterauth/public/mail.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="#666" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-mail-icon lucide-mail"><path d="m22 7-8.991 5.727a2 2 0 0 1-2.009 0L2 7"/><rect x="2" y="4" width="20" height="16" rx="2"/></svg>
|
||||
|
After Width: | Height: | Size: 301 B |
1
examples/betterauth/public/social/github.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>GitHub</title><path d="M12 .297c-6.63 0-12 5.373-12 12 0 5.303 3.438 9.8 8.205 11.385.6.113.82-.258.82-.577 0-.285-.01-1.04-.015-2.04-3.338.724-4.042-1.61-4.042-1.61C4.422 18.07 3.633 17.7 3.633 17.7c-1.087-.744.084-.729.084-.729 1.205.084 1.838 1.236 1.838 1.236 1.07 1.835 2.809 1.305 3.495.998.108-.776.417-1.305.76-1.605-2.665-.3-5.466-1.332-5.466-5.93 0-1.31.465-2.38 1.235-3.22-.135-.303-.54-1.523.105-3.176 0 0 1.005-.322 3.3 1.23.96-.267 1.98-.399 3-.405 1.02.006 2.04.138 3 .405 2.28-1.552 3.285-1.23 3.285-1.23.645 1.653.24 2.873.12 3.176.765.84 1.23 1.91 1.23 3.22 0 4.61-2.805 5.625-5.475 5.92.42.36.81 1.096.81 2.22 0 1.606-.015 2.896-.015 3.286 0 .315.21.69.825.57C20.565 22.092 24 17.592 24 12.297c0-6.627-5.373-12-12-12"/></svg>
|
||||
|
After Width: | Height: | Size: 823 B |
1
examples/betterauth/public/window.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg fill="none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path fill-rule="evenodd" clip-rule="evenodd" d="M1.5 2.5h13v10a1 1 0 0 1-1 1h-11a1 1 0 0 1-1-1zM0 1h16v11.5a2.5 2.5 0 0 1-2.5 2.5h-11A2.5 2.5 0 0 1 0 12.5zm3.75 4.5a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5M7 4.75a.75.75 0 1 1-1.5 0 .75.75 0 0 1 1.5 0m1.75.75a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5" fill="#666"/></svg>
|
||||
|
After Width: | Height: | Size: 385 B |
1
examples/betterauth/public/wrench.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="#666" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-wrench-icon lucide-wrench"><path d="M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.77-3.77a6 6 0 0 1-7.94 7.94l-6.91 6.91a2.12 2.12 0 0 1-3-3l6.91-6.91a6 6 0 0 1 7.94-7.94l-3.76 3.76z"/></svg>
|
||||
|
After Width: | Height: | Size: 369 B |
10
examples/betterauth/src/app/api/auth/[...all]/route.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import { auth } from "@/lib/auth";
|
||||
import { toNextJsHandler } from "better-auth/next-js";
|
||||
|
||||
export const { GET, POST } = (() => {
|
||||
if (!process.env.NEXT_PUBLIC_AUTH_BASE_URL) {
|
||||
return toNextJsHandler(auth.handler);
|
||||
} else {
|
||||
return { GET: undefined, POST: undefined };
|
||||
}
|
||||
})();
|
||||
10
examples/betterauth/src/app/delete-account/page.tsx
Normal file
@@ -0,0 +1,10 @@
|
||||
"use client";
|
||||
|
||||
import { useAccount } from "jazz-react";
|
||||
import { redirect } from "next/navigation";
|
||||
|
||||
export default function Page() {
|
||||
const { logOut } = useAccount({ resolve: { profile: true } });
|
||||
logOut();
|
||||
redirect("/");
|
||||
}
|
||||
BIN
examples/betterauth/src/app/favicon.ico
Normal file
|
After Width: | Height: | Size: 3.2 KiB |
7
examples/betterauth/src/app/forgot/page.tsx
Normal file
@@ -0,0 +1,7 @@
|
||||
"use client";
|
||||
|
||||
import ForgotForm from "@/components/forms/Forgot";
|
||||
|
||||
export default function ForgotPage() {
|
||||
return <ForgotForm />;
|
||||
}
|
||||
27
examples/betterauth/src/app/globals.css
Normal file
@@ -0,0 +1,27 @@
|
||||
@import "tailwindcss";
|
||||
@import "tailwindcss/utilities";
|
||||
|
||||
:root {
|
||||
--background: #ffffff;
|
||||
--foreground: #171717;
|
||||
}
|
||||
|
||||
@theme inline {
|
||||
--color-background: var(--background);
|
||||
--color-foreground: var(--foreground);
|
||||
--font-sans: var(--font-geist-sans);
|
||||
--font-mono: var(--font-geist-mono);
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: dark) {
|
||||
:root {
|
||||
--background: #0a0a0a;
|
||||
--foreground: #ededed;
|
||||
}
|
||||
}
|
||||
|
||||
body {
|
||||
background: var(--background);
|
||||
color: var(--foreground);
|
||||
font-family: Arial, Helvetica, sans-serif;
|
||||
}
|
||||
35
examples/betterauth/src/app/layout.tsx
Normal file
@@ -0,0 +1,35 @@
|
||||
import type { Metadata } from "next";
|
||||
import { Geist, Geist_Mono } from "next/font/google";
|
||||
import "./globals.css";
|
||||
import { JazzAndAuth } from "@/components/JazzAndAuth";
|
||||
|
||||
const geistSans = Geist({
|
||||
variable: "--font-geist-sans",
|
||||
subsets: ["latin"],
|
||||
});
|
||||
|
||||
const geistMono = Geist_Mono({
|
||||
variable: "--font-geist-mono",
|
||||
subsets: ["latin"],
|
||||
});
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: "Jazz Example: Better Auth",
|
||||
description: "Jazz example application demonstrating Better Auth integration",
|
||||
};
|
||||
|
||||
export default function RootLayout({
|
||||
children,
|
||||
}: Readonly<{
|
||||
children: React.ReactNode;
|
||||
}>) {
|
||||
return (
|
||||
<html lang="en">
|
||||
<body
|
||||
className={`${geistSans.variable} ${geistMono.variable} antialiased`}
|
||||
>
|
||||
<JazzAndAuth>{children}</JazzAndAuth>
|
||||
</body>
|
||||
</html>
|
||||
);
|
||||
}
|
||||
5
examples/betterauth/src/app/magic-link/logIn/page.tsx
Normal file
@@ -0,0 +1,5 @@
|
||||
"use client";
|
||||
|
||||
import MagicLinkSignIn from "@/components/routes/magic-link/signIn/page";
|
||||
|
||||
export default MagicLinkSignIn;
|
||||
5
examples/betterauth/src/app/magic-link/signIn/page.tsx
Normal file
@@ -0,0 +1,5 @@
|
||||
"use client";
|
||||
|
||||
import MagicLinkSignUp from "@/components/routes/magic-link/logIn/page";
|
||||
|
||||
export default MagicLinkSignUp;
|
||||
@@ -0,0 +1,11 @@
|
||||
"use client";
|
||||
|
||||
import { Verify } from "@/components/emails";
|
||||
|
||||
export default function Page() {
|
||||
const searchParams = new URLSearchParams(window.location.search);
|
||||
const name = searchParams.get("name") ?? undefined;
|
||||
const url = searchParams.get("url") ?? undefined;
|
||||
const otp = searchParams.get("otp") ?? undefined;
|
||||
return <Verify name={name} url={url} otp={otp}></Verify>;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
"use client";
|
||||
|
||||
import { Reset } from "@/components/emails";
|
||||
|
||||
export default function Page() {
|
||||
const searchParams = new URLSearchParams(window.location.search);
|
||||
const name = searchParams.get("name") ?? undefined;
|
||||
const url = searchParams.get("url") ?? undefined;
|
||||
const otp = searchParams.get("otp") ?? undefined;
|
||||
return <Reset name={name} url={url} otp={otp}></Reset>;
|
||||
}
|
||||
11
examples/betterauth/src/app/mockEmail/sign-in/page.tsx
Normal file
@@ -0,0 +1,11 @@
|
||||
"use client";
|
||||
|
||||
import { Login } from "@/components/emails";
|
||||
|
||||
export default function Page() {
|
||||
const searchParams = new URLSearchParams(window.location.search);
|
||||
const name = searchParams.get("name") ?? undefined;
|
||||
const url = searchParams.get("url") ?? undefined;
|
||||
const otp = searchParams.get("otp") ?? undefined;
|
||||
return <Login name={name} url={url} otp={otp}></Login>;
|
||||
}
|
||||
7
examples/betterauth/src/app/mockEmail/welcome/page.tsx
Normal file
@@ -0,0 +1,7 @@
|
||||
"use client";
|
||||
|
||||
import { Welcome } from "@/components/emails";
|
||||
|
||||
export default function Page() {
|
||||
return <Welcome></Welcome>;
|
||||
}
|
||||
165
examples/betterauth/src/app/page.tsx
Normal file
@@ -0,0 +1,165 @@
|
||||
"use client";
|
||||
|
||||
import { Button } from "@/components/Button";
|
||||
import { useAccount, useIsAuthenticated } from "jazz-react";
|
||||
import { useAuth } from "jazz-react-auth-betterauth";
|
||||
import Image from "next/image";
|
||||
import { useCallback } from "react";
|
||||
|
||||
export default function Home() {
|
||||
const { authClient, account, state } = useAuth();
|
||||
const hasCredentials = state !== "anonymous";
|
||||
const { me, logOut } = useAccount({ resolve: { profile: {} } });
|
||||
const isAuthenticated = useIsAuthenticated();
|
||||
const signOut = useCallback(() => {
|
||||
authClient.signOut().catch(console.error).finally(logOut);
|
||||
}, [logOut, authClient]);
|
||||
console.log("me", me);
|
||||
console.log("account", account);
|
||||
console.log("state", state);
|
||||
console.log("hasCredentials", hasCredentials);
|
||||
console.log("isAuthenticated", isAuthenticated);
|
||||
|
||||
return (
|
||||
<>
|
||||
<header className="absolute p-4 top-0 left-0 w-full z-10 flex items-center justify-between gap-4">
|
||||
<div className="float-start flex gap-4">
|
||||
{me && hasCredentials && isAuthenticated && (
|
||||
<>
|
||||
<Button onClick={signOut}>Sign out</Button>
|
||||
<Button href="/settings">Settings</Button>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
<div className="float-end flex gap-4">
|
||||
{!hasCredentials && !isAuthenticated && (
|
||||
<>
|
||||
<Button href="/sign-in" variant="secondary">
|
||||
Sign in
|
||||
</Button>
|
||||
<Button href="/sign-up">Sign up</Button>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</header>
|
||||
<div className="grid grid-rows-[20px_1fr_20px] items-center justify-items-center min-h-screen p-8 pb-20 gap-16 sm:p-20 font-[family-name:var(--font-geist-sans)]">
|
||||
<main className="flex flex-col gap-[32px] row-start-2 items-center sm:items-start">
|
||||
<Image
|
||||
src="/jazz-logo.svg"
|
||||
alt="Jazz logo"
|
||||
width={180}
|
||||
height={38}
|
||||
priority
|
||||
/>
|
||||
<p className="text-sm/6 text-center sm:text-left font-[family-name:var(--font-geist-mono)]">
|
||||
{me && hasCredentials && isAuthenticated && (
|
||||
<>
|
||||
{"Signed in as "}
|
||||
<span className="bg-black/[.05] dark:bg-white/[.06] px-1 py-0.5 rounded font-[family-name:var(--font-geist-mono)] font-semibold">
|
||||
{me.profile.name}
|
||||
</span>
|
||||
.
|
||||
</>
|
||||
)}
|
||||
{!hasCredentials && !isAuthenticated && <>Not signed in.</>}
|
||||
{!hasCredentials && isAuthenticated && (
|
||||
<>Not connected to the authentication server.</>
|
||||
)}
|
||||
{hasCredentials && !isAuthenticated && (
|
||||
<>Authenticated, but not logged in. Try refreshing.</>
|
||||
)}
|
||||
</p>
|
||||
|
||||
<div className="flex gap-4 items-center flex-col sm:flex-row">
|
||||
<a
|
||||
className="rounded-full border border-solid border-transparent transition-colors flex items-center justify-center bg-foreground text-background gap-2 hover:bg-[#383838] dark:hover:bg-[#ccc] font-medium text-sm sm:text-base h-10 sm:h-12 px-4 sm:px-5 sm:w-auto"
|
||||
href="https://jazz.tools/"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
<Image src="/jazz.svg" alt="Jazz logo" width={20} height={20} />
|
||||
Start building
|
||||
</a>
|
||||
<a
|
||||
className="rounded-full border border-solid border-black/[.08] dark:border-white/[.145] transition-colors flex items-center justify-center gap-2 hover:bg-[#f2f2f2] dark:hover:bg-[#1a1a1a] hover:border-transparent font-medium text-sm sm:text-base h-10 sm:h-12 px-4 sm:px-5 w-full sm:w-auto"
|
||||
href="https://jazz.tools/docs"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
<Image
|
||||
aria-hidden
|
||||
src="/file.svg"
|
||||
alt="File icon"
|
||||
width={16}
|
||||
height={16}
|
||||
/>
|
||||
Read the docs
|
||||
</a>
|
||||
</div>
|
||||
</main>
|
||||
<footer className="row-start-3 flex gap-[24px] flex-wrap items-center justify-center">
|
||||
<a
|
||||
className="flex items-center gap-2 hover:underline hover:underline-offset-4"
|
||||
href="https://jazz.tools/api-reference"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
<Image
|
||||
aria-hidden
|
||||
src="/file.svg"
|
||||
alt="File icon"
|
||||
width={16}
|
||||
height={16}
|
||||
/>
|
||||
API reference
|
||||
</a>
|
||||
<a
|
||||
className="flex items-center gap-2 hover:underline hover:underline-offset-4"
|
||||
href="https://jazz.tools/examples"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
<Image
|
||||
aria-hidden
|
||||
src="/window.svg"
|
||||
alt="Window icon"
|
||||
width={16}
|
||||
height={16}
|
||||
/>
|
||||
Examples
|
||||
</a>
|
||||
<a
|
||||
className="flex items-center gap-2 hover:underline hover:underline-offset-4"
|
||||
href="https://jazz.tools/status"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
<Image
|
||||
aria-hidden
|
||||
src="/globe.svg"
|
||||
alt="Globe icon"
|
||||
width={16}
|
||||
height={16}
|
||||
/>
|
||||
Status
|
||||
</a>
|
||||
<a
|
||||
className="flex items-center gap-2 hover:underline hover:underline-offset-4"
|
||||
href="https://jazz.tools/showcase"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
<Image
|
||||
aria-hidden
|
||||
src="/wrench.svg"
|
||||
alt="Wrench icon"
|
||||
width={16}
|
||||
height={16}
|
||||
/>
|
||||
Built with Jazz
|
||||
</a>
|
||||
</footer>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
7
examples/betterauth/src/app/pages/api/auth/[...all].ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import { auth } from "@/lib/auth";
|
||||
import { toNodeHandler } from "better-auth/node";
|
||||
|
||||
// Disallow body parsing, we will parse it manually
|
||||
export const config = { api: { bodyParser: false } };
|
||||
|
||||
export default toNodeHandler(auth.handler);
|
||||
7
examples/betterauth/src/app/reset/page.tsx
Normal file
@@ -0,0 +1,7 @@
|
||||
"use client";
|
||||
|
||||
import ResetForm from "@/components/forms/Reset";
|
||||
|
||||
export default function ResetPage() {
|
||||
return <ResetForm />;
|
||||
}
|
||||
7
examples/betterauth/src/app/settings/page.tsx
Normal file
@@ -0,0 +1,7 @@
|
||||
"use client";
|
||||
|
||||
import SettingsForm from "@/components/forms/Settings";
|
||||
|
||||
export default function SettingsPage() {
|
||||
return <SettingsForm providers={["github"]} />;
|
||||
}
|
||||
7
examples/betterauth/src/app/sign-in/page.tsx
Normal file
@@ -0,0 +1,7 @@
|
||||
"use client";
|
||||
|
||||
import SignInForm from "@/components/forms/SignIn";
|
||||
|
||||
export default function SignInPage() {
|
||||
return <SignInForm providers={["github"]} />;
|
||||
}
|
||||
7
examples/betterauth/src/app/sign-up/page.tsx
Normal file
@@ -0,0 +1,7 @@
|
||||
"use client";
|
||||
|
||||
import SignUpForm from "@/components/forms/SignUp";
|
||||
|
||||
export default function SignUpPage() {
|
||||
return <SignUpForm providers={["github"]} />;
|
||||
}
|
||||
10
examples/betterauth/src/app/social/logIn/page.tsx
Normal file
@@ -0,0 +1,10 @@
|
||||
"use client";
|
||||
|
||||
import { useAuth } from "jazz-react-auth-betterauth";
|
||||
import { redirect } from "next/navigation";
|
||||
|
||||
export default function Page() {
|
||||
const { logIn } = useAuth();
|
||||
logIn().then(redirect("/"));
|
||||
return null;
|
||||
}
|
||||
10
examples/betterauth/src/app/social/signIn/page.tsx
Normal file
@@ -0,0 +1,10 @@
|
||||
"use client";
|
||||
|
||||
import { useAuth } from "jazz-react-auth-betterauth";
|
||||
import { redirect } from "next/navigation";
|
||||
|
||||
export default function Page() {
|
||||
const { signIn } = useAuth();
|
||||
signIn().then(redirect("/"));
|
||||
return null;
|
||||
}
|
||||
85
examples/betterauth/src/components/AccountProviders.tsx
Normal file
@@ -0,0 +1,85 @@
|
||||
import { Button } from "@/components/Button";
|
||||
import { AccountsType, useAuth } from "jazz-react-auth-betterauth";
|
||||
|
||||
export const AccountProviders = ({
|
||||
setLoading,
|
||||
setError,
|
||||
accounts,
|
||||
}: {
|
||||
setLoading: React.Dispatch<React.SetStateAction<boolean>>;
|
||||
setError: React.Dispatch<React.SetStateAction<Error | undefined>>;
|
||||
accounts: AccountsType | undefined;
|
||||
}) => {
|
||||
const auth = useAuth();
|
||||
return (
|
||||
<table className="w-full text-sm border-full border-collapse">
|
||||
<thead className="text-xs">
|
||||
<tr>
|
||||
<th scope="col" className="px-6 py-3">
|
||||
Provider
|
||||
</th>
|
||||
<th scope="col" className="px-6 py-3">
|
||||
Created
|
||||
</th>
|
||||
<th scope="col" className="px-6 py-3">
|
||||
Updated
|
||||
</th>
|
||||
<th scope="col" className="px-6 py-3">
|
||||
Scopes
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{!accounts?.data?.length && "No authentication providers found"}
|
||||
{accounts?.data &&
|
||||
accounts.data.map((account) => (
|
||||
<tr key={account.id} className="border-b">
|
||||
<th
|
||||
scope="row"
|
||||
className="px-6 py-4 font-medium whitespace-nowrap"
|
||||
>
|
||||
{account.provider}
|
||||
</th>
|
||||
<td className="px-6 py-4">
|
||||
{account.createdAt.toLocaleString()}
|
||||
</td>
|
||||
<td className="px-6 py-4">
|
||||
{account.updatedAt.toLocaleString()}
|
||||
</td>
|
||||
<td className="px-6 py-4">{account.scopes.join(", ")}</td>
|
||||
<td className="px-6 py-4">
|
||||
<Button
|
||||
variant="secondary"
|
||||
className="relative"
|
||||
onClick={async (e) => {
|
||||
e.preventDefault();
|
||||
setLoading(true);
|
||||
const { error } = await auth.authClient.unlinkAccount({
|
||||
providerId: account.provider,
|
||||
accountId: account.id,
|
||||
});
|
||||
const errorMessage = error?.message ?? error?.statusText;
|
||||
setError(
|
||||
error
|
||||
? {
|
||||
...error,
|
||||
name: error.statusText,
|
||||
message:
|
||||
errorMessage && errorMessage.length > 0
|
||||
? errorMessage
|
||||
: "An error occurred",
|
||||
}
|
||||
: undefined,
|
||||
);
|
||||
setLoading(false);
|
||||
}}
|
||||
>
|
||||
Unlink
|
||||
</Button>
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
);
|
||||
};
|
||||
92
examples/betterauth/src/components/Button.tsx
Normal file
@@ -0,0 +1,92 @@
|
||||
import { clsx } from "clsx";
|
||||
import Image from "next/image";
|
||||
import Link from "next/link";
|
||||
import { forwardRef } from "react";
|
||||
|
||||
interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
|
||||
variant?: "primary" | "secondary" | "danger";
|
||||
children?: React.ReactNode;
|
||||
className?: string;
|
||||
src?: string;
|
||||
alt?: string;
|
||||
imageClassName?: string;
|
||||
href?: string;
|
||||
newTab?: boolean;
|
||||
}
|
||||
|
||||
export const Button = forwardRef<HTMLButtonElement, ButtonProps>(
|
||||
(
|
||||
{
|
||||
className,
|
||||
children,
|
||||
variant = "primary",
|
||||
src,
|
||||
alt,
|
||||
imageClassName,
|
||||
href,
|
||||
newTab = false,
|
||||
...buttonProps
|
||||
},
|
||||
ref,
|
||||
) => {
|
||||
const primary =
|
||||
"rounded-full border border-solid border-transparent transition-colors flex items-center justify-center bg-foreground text-background gap-2 hover:bg-[#383838] dark:hover:bg-[#ccc] font-medium text-sm sm:text-base h-10 sm:h-12 px-4 sm:px-5 sm:w-auto";
|
||||
const secondary =
|
||||
"rounded-full border border-solid border-black/[.08] dark:border-white/[.145] transition-colors flex items-center justify-center gap-2 hover:bg-[#f2f2f2] dark:hover:bg-[#1a1a1a] hover:border-transparent font-medium text-sm sm:text-base h-10 sm:h-12 px-4 sm:px-5 w-full sm:w-auto";
|
||||
const danger =
|
||||
"rounded-full border border-solid border-black/[.08] dark:border-white/[.145] transition-colors flex items-center justify-center bg-red-400 dark:bg-red-600 gap-2 hover:bg-red-300 dark:hover:bg-red-700 hover:border-transparent font-medium text-sm sm:text-base h-10 sm:h-12 px-4 sm:px-5 w-full sm:w-auto";
|
||||
const classes = clsx(
|
||||
variant === "primary"
|
||||
? primary
|
||||
: variant === "secondary"
|
||||
? secondary
|
||||
: danger,
|
||||
className,
|
||||
);
|
||||
const [width, height] = [
|
||||
variant === "primary" ? 20 : 16,
|
||||
variant === "primary" ? 20 : 16,
|
||||
];
|
||||
if (href) {
|
||||
return (
|
||||
<Link
|
||||
href={href}
|
||||
target={newTab ? "_blank" : undefined}
|
||||
className={classes}
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
{src && alt && (
|
||||
<Image
|
||||
className={imageClassName}
|
||||
src={src}
|
||||
alt={alt}
|
||||
width={width}
|
||||
height={height}
|
||||
/>
|
||||
)}
|
||||
{children}
|
||||
</Link>
|
||||
);
|
||||
} else {
|
||||
return (
|
||||
<button
|
||||
ref={ref}
|
||||
{...buttonProps}
|
||||
className={classes}
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
{src && alt && (
|
||||
<Image
|
||||
className={imageClassName}
|
||||
src={src}
|
||||
alt={alt}
|
||||
width={width}
|
||||
height={height}
|
||||
/>
|
||||
)}
|
||||
{children}
|
||||
</button>
|
||||
);
|
||||
}
|
||||
},
|
||||
);
|
||||
56
examples/betterauth/src/components/DeleteAccountButton.tsx
Normal file
@@ -0,0 +1,56 @@
|
||||
import { Button } from "@/components/Button";
|
||||
import { useAuth } from "jazz-react-auth-betterauth";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { forwardRef } from "react";
|
||||
|
||||
interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
|
||||
children?: React.ReactNode;
|
||||
src?: InstanceType<typeof Image>["src"];
|
||||
alt?: InstanceType<typeof Image>["alt"];
|
||||
callbackURL: string;
|
||||
setLoading: React.Dispatch<React.SetStateAction<boolean>>;
|
||||
setError: React.Dispatch<React.SetStateAction<Error | undefined>>;
|
||||
}
|
||||
|
||||
export const DeleteAccountButton = forwardRef<HTMLButtonElement, ButtonProps>(
|
||||
({ callbackURL, setLoading, setError }) => {
|
||||
const router = useRouter();
|
||||
const auth = useAuth();
|
||||
return (
|
||||
<Button
|
||||
variant="danger"
|
||||
className="relative"
|
||||
onClick={async (e) => {
|
||||
e.preventDefault();
|
||||
setLoading(true);
|
||||
const { error } = await auth.authClient.deleteUser(
|
||||
{
|
||||
callbackURL: callbackURL,
|
||||
},
|
||||
{
|
||||
onSuccess: () => {
|
||||
router.replace(callbackURL);
|
||||
},
|
||||
},
|
||||
);
|
||||
const errorMessage = error?.message ?? error?.statusText;
|
||||
setError(
|
||||
error
|
||||
? {
|
||||
...error,
|
||||
name: error.statusText,
|
||||
message:
|
||||
errorMessage && errorMessage.length > 0
|
||||
? errorMessage
|
||||
: "An error occurred",
|
||||
}
|
||||
: undefined,
|
||||
);
|
||||
setLoading(false);
|
||||
}}
|
||||
>
|
||||
Delete account
|
||||
</Button>
|
||||
);
|
||||
},
|
||||
);
|
||||
37
examples/betterauth/src/components/JazzAndAuth.tsx
Normal file
@@ -0,0 +1,37 @@
|
||||
"use client";
|
||||
|
||||
import { emailOTPClient, magicLinkClient } from "better-auth/client/plugins";
|
||||
import { JazzProvider } from "jazz-react";
|
||||
import { AuthProvider } from "jazz-react-auth-betterauth";
|
||||
import { type ReactNode, lazy } from "react";
|
||||
|
||||
const JazzDevTools =
|
||||
process.env.NODE_ENV === "production"
|
||||
? () => null
|
||||
: lazy(() =>
|
||||
import("jazz-inspector").then((res) => ({
|
||||
default: res.JazzInspector,
|
||||
})),
|
||||
);
|
||||
|
||||
export function JazzAndAuth({ children }: { children: ReactNode }) {
|
||||
return (
|
||||
<JazzProvider
|
||||
sync={{
|
||||
peer: "wss://cloud.jazz.tools/?key=betterauth-example@garden.co",
|
||||
}}
|
||||
>
|
||||
<>
|
||||
<AuthProvider
|
||||
options={{
|
||||
baseURL: process.env.NEXT_PUBLIC_AUTH_BASE_URL,
|
||||
plugins: [magicLinkClient(), emailOTPClient()],
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
</AuthProvider>
|
||||
<JazzDevTools />
|
||||
</>
|
||||
</JazzProvider>
|
||||
);
|
||||
}
|
||||
7
examples/betterauth/src/components/Loading.tsx
Normal file
@@ -0,0 +1,7 @@
|
||||
export function Loading() {
|
||||
return (
|
||||
<div className="flex h-full items-center justify-center">
|
||||
<div className="h-8 w-8 animate-spin rounded-full border-4 border-primary border-t-transparent" />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
73
examples/betterauth/src/components/SSOButton.tsx
Normal file
@@ -0,0 +1,73 @@
|
||||
import { Button } from "@/components/Button";
|
||||
import { SSOProviderType, useAuth } from "jazz-react-auth-betterauth";
|
||||
import { socialProviderNames } from "jazz-react-auth-betterauth";
|
||||
import { forwardRef } from "react";
|
||||
|
||||
interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
|
||||
children?: React.ReactNode;
|
||||
src?: InstanceType<typeof Image>["src"];
|
||||
alt?: InstanceType<typeof Image>["alt"];
|
||||
provider: SSOProviderType;
|
||||
link?: boolean;
|
||||
callbackURL?: string;
|
||||
setLoading: React.Dispatch<React.SetStateAction<boolean>>;
|
||||
setError: React.Dispatch<React.SetStateAction<Error | undefined>>;
|
||||
}
|
||||
|
||||
export const SSOButton = forwardRef<HTMLButtonElement, ButtonProps>(
|
||||
(
|
||||
{
|
||||
children,
|
||||
provider,
|
||||
link = false,
|
||||
callbackURL,
|
||||
setLoading,
|
||||
setError,
|
||||
...buttonProps
|
||||
},
|
||||
ref,
|
||||
) => {
|
||||
const auth = useAuth();
|
||||
const providerName = socialProviderNames[provider];
|
||||
return (
|
||||
<Button
|
||||
src={`/social/${provider}.svg`}
|
||||
alt={`${providerName} logo`}
|
||||
imageClassName="absolute left-3 dark:invert"
|
||||
variant="secondary"
|
||||
className="relative"
|
||||
onClick={async (e) => {
|
||||
e.preventDefault();
|
||||
setLoading(true);
|
||||
const { error } = await (async () => {
|
||||
if (link) {
|
||||
return await auth.authClient.linkSocial({
|
||||
provider: provider,
|
||||
});
|
||||
} else {
|
||||
return await auth.authClient.signIn.social({
|
||||
provider: provider,
|
||||
callbackURL: callbackURL,
|
||||
});
|
||||
}
|
||||
})();
|
||||
if (error) {
|
||||
setError({
|
||||
...error,
|
||||
name: error.message ?? error.statusText,
|
||||
message: error.message ?? error.statusText,
|
||||
});
|
||||
}
|
||||
setLoading(false);
|
||||
}}
|
||||
{...buttonProps}
|
||||
ref={ref}
|
||||
>
|
||||
{link
|
||||
? `Link ${providerName} account`
|
||||
: `Continue with ${providerName}`}
|
||||
{children}
|
||||
</Button>
|
||||
);
|
||||
},
|
||||
);
|
||||
66
examples/betterauth/src/components/emails/Common.ts
Normal file
@@ -0,0 +1,66 @@
|
||||
export const appName = "Jazz Example App";
|
||||
|
||||
export const main = {
|
||||
backgroundColor: "#f6f9fc",
|
||||
padding: "10px 0",
|
||||
};
|
||||
|
||||
export const container = {
|
||||
backgroundColor: "#ffffff",
|
||||
border: "1px solid #f0f0f0",
|
||||
padding: "45px",
|
||||
};
|
||||
|
||||
export const text = {
|
||||
fontSize: "16px",
|
||||
fontFamily:
|
||||
"'Open Sans', 'HelveticaNeue-Light', 'Helvetica Neue Light', 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif",
|
||||
fontWeight: "300",
|
||||
color: "#404040",
|
||||
lineHeight: "26px",
|
||||
};
|
||||
|
||||
export const h1 = {
|
||||
...text,
|
||||
fontSize: "24px",
|
||||
fontWeight: "bold",
|
||||
};
|
||||
|
||||
export const button = {
|
||||
backgroundColor: "#146AFF",
|
||||
borderRadius: "4px",
|
||||
color: "#fff",
|
||||
fontFamily: "'Open Sans', 'Helvetica Neue', Arial",
|
||||
fontSize: "15px",
|
||||
textDecoration: "none",
|
||||
textAlign: "center" as const,
|
||||
display: "block",
|
||||
width: "210px",
|
||||
padding: "14px 7px",
|
||||
};
|
||||
|
||||
export const anchor = {
|
||||
textDecoration: "underline",
|
||||
};
|
||||
|
||||
export const codeContainer = {
|
||||
background: "rgba(0,0,0,.05)",
|
||||
borderRadius: "4px",
|
||||
margin: "16px auto 14px",
|
||||
verticalAlign: "middle",
|
||||
width: "280px",
|
||||
};
|
||||
|
||||
export const code = {
|
||||
color: "#000",
|
||||
fontFamily: "HelveticaNeue-Bold",
|
||||
fontSize: "32px",
|
||||
fontWeight: 700,
|
||||
letterSpacing: "6px",
|
||||
lineHeight: "40px",
|
||||
paddingBottom: "8px",
|
||||
paddingTop: "8px",
|
||||
margin: "0 auto",
|
||||
display: "block",
|
||||
textAlign: "center" as const,
|
||||
};
|
||||
91
examples/betterauth/src/components/emails/Login.tsx
Normal file
@@ -0,0 +1,91 @@
|
||||
import {
|
||||
Body,
|
||||
Button,
|
||||
Container,
|
||||
Head,
|
||||
Heading,
|
||||
Html,
|
||||
Preview,
|
||||
Section,
|
||||
Text,
|
||||
} from "@react-email/components";
|
||||
import Image from "next/image";
|
||||
import * as React from "react";
|
||||
import {
|
||||
appName,
|
||||
button,
|
||||
code,
|
||||
codeContainer,
|
||||
container,
|
||||
h1,
|
||||
main,
|
||||
text,
|
||||
} from "./Common";
|
||||
|
||||
export const Login = ({
|
||||
name = undefined,
|
||||
url = undefined,
|
||||
otp = undefined,
|
||||
}: {
|
||||
name?: string;
|
||||
url?: string;
|
||||
otp?: string;
|
||||
}) => {
|
||||
return (
|
||||
<Html>
|
||||
<Head>
|
||||
<title>
|
||||
{url && !otp
|
||||
? `Your login link for ${appName}`
|
||||
: `Your login code for ${appName}`}
|
||||
</title>
|
||||
</Head>
|
||||
<Preview>
|
||||
{url && !otp
|
||||
? `Your login link for ${appName}`
|
||||
: `Your login code for ${appName}`}
|
||||
</Preview>
|
||||
<Body style={main}>
|
||||
<Container style={container}>
|
||||
<Image
|
||||
src="/jazz.svg"
|
||||
alt="Jazz logo"
|
||||
width={100}
|
||||
height={100}
|
||||
priority
|
||||
/>
|
||||
<Heading style={h1}>
|
||||
{url && !otp
|
||||
? `Your login link for ${appName}`
|
||||
: `Your login code for ${appName}`}
|
||||
</Heading>
|
||||
<Section>
|
||||
<Text style={text}>Hello{name ? ` ${name}` : ""},</Text>
|
||||
<Text style={text}>
|
||||
Someone recently attempted to login to {appName} using your email
|
||||
address.
|
||||
{url && !otp ? " If this was you, you can login here:" : ""}
|
||||
</Text>
|
||||
{url && !otp && (
|
||||
<Button style={button} href={url}>
|
||||
Login
|
||||
</Button>
|
||||
)}
|
||||
{otp && !url && (
|
||||
<Section style={codeContainer}>
|
||||
<Text style={code}>{otp}</Text>
|
||||
</Section>
|
||||
)}
|
||||
<Text style={text}>
|
||||
To keep your account secure, please do not forward this email to
|
||||
anyone. If you did not try to login, just ignore and delete this
|
||||
message.
|
||||
</Text>
|
||||
</Section>
|
||||
</Container>
|
||||
</Body>
|
||||
</Html>
|
||||
);
|
||||
};
|
||||
|
||||
export default Login;
|
||||
84
examples/betterauth/src/components/emails/Reset.tsx
Normal file
@@ -0,0 +1,84 @@
|
||||
import {
|
||||
Body,
|
||||
Button,
|
||||
Container,
|
||||
Head,
|
||||
Heading,
|
||||
Html,
|
||||
Preview,
|
||||
Section,
|
||||
Text,
|
||||
} from "@react-email/components";
|
||||
import Image from "next/image";
|
||||
import * as React from "react";
|
||||
import {
|
||||
appName,
|
||||
button,
|
||||
code,
|
||||
codeContainer,
|
||||
container,
|
||||
h1,
|
||||
main,
|
||||
text,
|
||||
} from "./Common";
|
||||
|
||||
export const Reset = ({
|
||||
name = undefined,
|
||||
url = undefined,
|
||||
otp = undefined,
|
||||
}: {
|
||||
name?: string;
|
||||
url?: string;
|
||||
otp?: string;
|
||||
}) => {
|
||||
return (
|
||||
<Html>
|
||||
<Head>
|
||||
<title>{`Reset your ${appName} password`}</title>
|
||||
</Head>
|
||||
<Preview>Reset your {appName} password</Preview>
|
||||
<Body style={main}>
|
||||
<Container style={container}>
|
||||
<Image
|
||||
src="/jazz.svg"
|
||||
alt="Jazz logo"
|
||||
width={100}
|
||||
height={100}
|
||||
priority
|
||||
/>
|
||||
<Heading style={h1}>Reset your {appName} password</Heading>
|
||||
<Section>
|
||||
<Text style={text}>Hello{name ? ` ${name}` : ""},</Text>
|
||||
<Text style={text}>
|
||||
Someone recently requested a password change for your {appName}{" "}
|
||||
account.
|
||||
{url && !otp
|
||||
? " If this was you, you can set a new password here:"
|
||||
: ""}
|
||||
</Text>
|
||||
{url && !otp && (
|
||||
<Button style={button} href={url}>
|
||||
Reset password
|
||||
</Button>
|
||||
)}
|
||||
{otp && !url && (
|
||||
<Section style={codeContainer}>
|
||||
<Text style={code}>{otp}</Text>
|
||||
</Section>
|
||||
)}
|
||||
<Text style={text}>
|
||||
If you do not want to change your password or did not request
|
||||
this, just ignore and delete this message.
|
||||
</Text>
|
||||
<Text style={text}>
|
||||
To keep your account secure, please do not forward this email to
|
||||
anyone.
|
||||
</Text>
|
||||
</Section>
|
||||
</Container>
|
||||
</Body>
|
||||
</Html>
|
||||
);
|
||||
};
|
||||
|
||||
export default Reset;
|
||||
80
examples/betterauth/src/components/emails/Verify.tsx
Normal file
@@ -0,0 +1,80 @@
|
||||
import {
|
||||
Body,
|
||||
Button,
|
||||
Container,
|
||||
Head,
|
||||
Heading,
|
||||
Html,
|
||||
Preview,
|
||||
Section,
|
||||
Text,
|
||||
} from "@react-email/components";
|
||||
import Image from "next/image";
|
||||
import * as React from "react";
|
||||
import {
|
||||
appName,
|
||||
button,
|
||||
code,
|
||||
codeContainer,
|
||||
container,
|
||||
h1,
|
||||
main,
|
||||
text,
|
||||
} from "./Common";
|
||||
|
||||
export const Verify = ({
|
||||
name = undefined,
|
||||
url = undefined,
|
||||
otp = undefined,
|
||||
}: {
|
||||
name?: string;
|
||||
url?: string;
|
||||
otp?: string;
|
||||
}) => {
|
||||
return (
|
||||
<Html>
|
||||
<Head>
|
||||
<title>{`Verify your ${appName} account`}</title>
|
||||
</Head>
|
||||
<Preview>Verify your {appName} account</Preview>
|
||||
<Body style={main}>
|
||||
<Container style={container}>
|
||||
<Image
|
||||
src="/jazz.svg"
|
||||
alt="Jazz logo"
|
||||
width={100}
|
||||
height={100}
|
||||
priority
|
||||
/>
|
||||
<Heading style={h1}>Verify your {appName} account</Heading>
|
||||
<Section>
|
||||
<Text style={text}>Hello{name ? ` ${name}` : ""},</Text>
|
||||
<Text style={text}>
|
||||
Someone recently signed up for a {appName} account using your
|
||||
email address.
|
||||
{url && !otp
|
||||
? " If this was you, you can verify your account here:"
|
||||
: ""}
|
||||
</Text>
|
||||
{url && !otp && (
|
||||
<Button style={button} href={url}>
|
||||
Verify account
|
||||
</Button>
|
||||
)}
|
||||
{otp && !url && (
|
||||
<Section style={codeContainer}>
|
||||
<Text style={code}>{otp}</Text>
|
||||
</Section>
|
||||
)}
|
||||
<Text style={text}>
|
||||
To keep your account secure, please do not forward this email to
|
||||
anyone.
|
||||
</Text>
|
||||
</Section>
|
||||
</Container>
|
||||
</Body>
|
||||
</Html>
|
||||
);
|
||||
};
|
||||
|
||||
export default Verify;
|
||||
53
examples/betterauth/src/components/emails/Welcome.tsx
Normal file
@@ -0,0 +1,53 @@
|
||||
import {
|
||||
Body,
|
||||
Button,
|
||||
Container,
|
||||
Head,
|
||||
Heading,
|
||||
Html,
|
||||
Preview,
|
||||
Row,
|
||||
Section,
|
||||
Text,
|
||||
} from "@react-email/components";
|
||||
import Image from "next/image";
|
||||
import * as React from "react";
|
||||
import { appName, button, container, h1, main, text } from "./Common";
|
||||
|
||||
export const Welcome = () => {
|
||||
return (
|
||||
<Html>
|
||||
<Head>
|
||||
<title>{`Welcome to ${appName}`}</title>
|
||||
</Head>
|
||||
<Preview>Welcome to {appName}</Preview>
|
||||
<Body style={main}>
|
||||
<Container style={container}>
|
||||
<Image
|
||||
src="/jazz.svg"
|
||||
alt="Jazz logo"
|
||||
width={100}
|
||||
height={100}
|
||||
priority
|
||||
/>
|
||||
<Heading style={h1}>Welcome to {appName}</Heading>
|
||||
<Section>
|
||||
<Row>
|
||||
<Text style={text}>
|
||||
Congratulations! You have successfully registered for {appName}.
|
||||
We are excited to have you on board!
|
||||
</Text>
|
||||
</Row>
|
||||
</Section>
|
||||
<Section>
|
||||
<Button style={button} href="/">
|
||||
Go home
|
||||
</Button>
|
||||
</Section>
|
||||
</Container>
|
||||
</Body>
|
||||
</Html>
|
||||
);
|
||||
};
|
||||
|
||||
export default Welcome;
|
||||
5
examples/betterauth/src/components/emails/index.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
export * from "./Common";
|
||||
export * from "./Welcome";
|
||||
export * from "./Verify";
|
||||
export * from "./Reset";
|
||||
export * from "./Login";
|
||||
199
examples/betterauth/src/components/forms/Forgot.tsx
Normal file
@@ -0,0 +1,199 @@
|
||||
import { Button } from "@/components/Button";
|
||||
import { Loading } from "@/components/Loading";
|
||||
import { useAuth } from "jazz-react-auth-betterauth";
|
||||
import type { FullAuthClient } from "jazz-react-auth-betterauth";
|
||||
import { useState } from "react";
|
||||
|
||||
const title = "Forgot Password";
|
||||
|
||||
export default function ForgotForm() {
|
||||
const auth = useAuth();
|
||||
const [email, setEmail] = useState<string>("");
|
||||
const [otp, setOtp] = useState<string>("");
|
||||
const [otpSentStatus, setOtpSentStatus] = useState<boolean>(false);
|
||||
const [otpStatus, setOtpStatus] = useState<boolean>(false);
|
||||
const [password, setPassword] = useState<string>("");
|
||||
const [confirmPassword, setConfirmPassword] = useState<string>("");
|
||||
const [status, setStatus] = useState<boolean>(false);
|
||||
const [loading, setLoading] = useState<boolean>(false);
|
||||
const [error, setError] = useState<Error | undefined>(undefined);
|
||||
|
||||
return (
|
||||
<div className="min-h-screen flex flex-col justify-center">
|
||||
<div className="max-w-md flex flex-col gap-8 w-full px-6 py-12 mx-auto">
|
||||
<div>
|
||||
<h1 className="text-stone-950 dark:text-white font-display text-5xl lg:text-6xl font-medium tracking-tighter mb-2">
|
||||
{title}
|
||||
</h1>
|
||||
<p>
|
||||
Enter your email address, and we'll send you a link to reset your
|
||||
password.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{status && !otpStatus && (
|
||||
<div>
|
||||
Instructions to reset your password have been sent to {email}, if an
|
||||
account with that email address exists.
|
||||
</div>
|
||||
)}
|
||||
|
||||
{otpStatus && (
|
||||
<div>
|
||||
Your password has been successfully reset. You may now log in.
|
||||
</div>
|
||||
)}
|
||||
|
||||
{error && <div>{error.message}</div>}
|
||||
|
||||
{loading && <Loading />}
|
||||
|
||||
<form className="flex flex-col gap-6">
|
||||
<div>
|
||||
<label htmlFor="email-address">Email address</label>
|
||||
<input
|
||||
id="email-address"
|
||||
value={email}
|
||||
disabled={loading}
|
||||
onChange={(e) => setEmail(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
<Button
|
||||
onClick={async (e) => {
|
||||
e.preventDefault();
|
||||
setLoading(true);
|
||||
const { data, error } = await auth.authClient.forgetPassword({
|
||||
email: email,
|
||||
redirectTo: `${window.location.origin}/reset`,
|
||||
});
|
||||
setStatus(data?.status ?? false);
|
||||
const errorMessage = error?.message ?? error?.statusText;
|
||||
setError(
|
||||
error
|
||||
? {
|
||||
...error,
|
||||
name: error.statusText,
|
||||
message:
|
||||
errorMessage && errorMessage.length > 0
|
||||
? errorMessage
|
||||
: "An error occurred",
|
||||
}
|
||||
: undefined,
|
||||
);
|
||||
setLoading(false);
|
||||
}}
|
||||
disabled={loading}
|
||||
>
|
||||
Send recovery link
|
||||
</Button>
|
||||
<Button
|
||||
onClick={async (e) => {
|
||||
e.preventDefault();
|
||||
setLoading(true);
|
||||
const { data, error } = await (
|
||||
auth.authClient as FullAuthClient
|
||||
).emailOtp.sendVerificationOtp({
|
||||
email: email,
|
||||
type: "forget-password",
|
||||
});
|
||||
setStatus(data?.success ?? false);
|
||||
setOtpSentStatus(data?.success ?? false);
|
||||
const errorMessage = error?.message ?? error?.statusText;
|
||||
setError(
|
||||
error
|
||||
? {
|
||||
...error,
|
||||
name: error.statusText,
|
||||
message:
|
||||
errorMessage && errorMessage.length > 0
|
||||
? errorMessage
|
||||
: "An error occurred",
|
||||
}
|
||||
: undefined,
|
||||
);
|
||||
setLoading(false);
|
||||
}}
|
||||
disabled={loading}
|
||||
>
|
||||
Send recovery one-time password
|
||||
</Button>
|
||||
</form>
|
||||
|
||||
{otpSentStatus && (
|
||||
<form
|
||||
className="flex flex-col gap-6"
|
||||
onSubmit={async (e) => {
|
||||
e.preventDefault();
|
||||
setLoading(true);
|
||||
if (password !== confirmPassword) {
|
||||
setError(new Error("Passwords do not match"));
|
||||
setLoading(false);
|
||||
return;
|
||||
}
|
||||
const { data, error } = await (
|
||||
auth.authClient as FullAuthClient
|
||||
).emailOtp.resetPassword({
|
||||
email: email,
|
||||
otp: otp,
|
||||
password: password,
|
||||
});
|
||||
setStatus(data?.success ?? false);
|
||||
setOtpStatus(data?.success ?? false);
|
||||
const errorMessage = error?.message ?? error?.statusText;
|
||||
setError(
|
||||
error
|
||||
? {
|
||||
...error,
|
||||
name: error.statusText,
|
||||
message:
|
||||
errorMessage && errorMessage.length > 0
|
||||
? errorMessage
|
||||
: "An error occurred",
|
||||
}
|
||||
: undefined,
|
||||
);
|
||||
setLoading(false);
|
||||
}}
|
||||
>
|
||||
<div>
|
||||
<label htmlFor="otp">One-time password</label>
|
||||
<input
|
||||
id="otp"
|
||||
value={otp}
|
||||
disabled={loading}
|
||||
onChange={(e) => setOtp(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label htmlFor="password">Password</label>
|
||||
<input
|
||||
id="password"
|
||||
type="password"
|
||||
value={password}
|
||||
disabled={loading}
|
||||
onChange={(e) => setPassword(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label htmlFor="confirm-password">Confirm password</label>
|
||||
<input
|
||||
id="confirm-password"
|
||||
type="password"
|
||||
value={confirmPassword}
|
||||
disabled={loading}
|
||||
onChange={(e) => setConfirmPassword(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
<Button type={"submit"} disabled={loading}>
|
||||
Submit
|
||||
</Button>
|
||||
</form>
|
||||
)}
|
||||
|
||||
<Button href="/sign-in" disabled={loading}>
|
||||
Sign in
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
115
examples/betterauth/src/components/forms/Reset.tsx
Normal file
@@ -0,0 +1,115 @@
|
||||
import { Button } from "@/components/Button";
|
||||
import { Loading } from "@/components/Loading";
|
||||
import { useAuth } from "jazz-react-auth-betterauth";
|
||||
import Link from "next/link";
|
||||
import { useState } from "react";
|
||||
|
||||
const title = "Reset Password";
|
||||
|
||||
export default function ResetForm() {
|
||||
const auth = useAuth();
|
||||
const searchParams = new URLSearchParams(window.location.search);
|
||||
const token = searchParams.get("token");
|
||||
const initialError = searchParams.get("error");
|
||||
const [error, setError] = useState<Error | undefined>(
|
||||
initialError
|
||||
? {
|
||||
name: initialError,
|
||||
message: initialError,
|
||||
}
|
||||
: undefined,
|
||||
);
|
||||
const [password, setPassword] = useState<string>("");
|
||||
const [confirmPassword, setConfirmPassword] = useState<string>("");
|
||||
const [status, setStatus] = useState<boolean>(false);
|
||||
const [loading, setLoading] = useState<boolean>(false);
|
||||
|
||||
return (
|
||||
<div className="min-h-screen flex flex-col justify-center">
|
||||
<div className="max-w-md flex flex-col gap-8 w-full px-6 py-12 mx-auto">
|
||||
<div>
|
||||
<h1 className="text-stone-950 dark:text-white font-display text-5xl lg:text-6xl font-medium tracking-tighter mb-2">
|
||||
{title}
|
||||
</h1>
|
||||
<p>Enter your new password.</p>
|
||||
</div>
|
||||
|
||||
{status && (
|
||||
<div>
|
||||
Your password has been reset. You may now{" "}
|
||||
<Link href="/sign-in">sign in</Link>.
|
||||
</div>
|
||||
)}
|
||||
|
||||
{error && <div>{error.message}</div>}
|
||||
|
||||
{loading && <Loading />}
|
||||
|
||||
<form
|
||||
className="flex flex-col gap-6"
|
||||
onSubmit={async (e) => {
|
||||
e.preventDefault();
|
||||
setLoading(true);
|
||||
if (password !== confirmPassword) {
|
||||
setError(new Error("Passwords do not match"));
|
||||
setLoading(false);
|
||||
return;
|
||||
}
|
||||
if (!token) {
|
||||
setError(new Error("No password reset token provided"));
|
||||
setLoading(false);
|
||||
return;
|
||||
}
|
||||
const { data, error } = await auth.authClient.resetPassword({
|
||||
newPassword: password,
|
||||
token,
|
||||
});
|
||||
setStatus(data?.status ?? false);
|
||||
const errorMessage = error?.message ?? error?.statusText;
|
||||
setError(
|
||||
error
|
||||
? {
|
||||
...error,
|
||||
name: error.statusText,
|
||||
message:
|
||||
errorMessage && errorMessage.length > 0
|
||||
? errorMessage
|
||||
: "An error occurred",
|
||||
}
|
||||
: undefined,
|
||||
);
|
||||
setLoading(false);
|
||||
}}
|
||||
>
|
||||
<div>
|
||||
<label htmlFor="password">Password</label>
|
||||
<input
|
||||
id="password"
|
||||
type="password"
|
||||
value={password}
|
||||
disabled={loading}
|
||||
onChange={(e) => setPassword(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label htmlFor="confirm-password">Confirm password</label>
|
||||
<input
|
||||
id="confirm-password"
|
||||
type="password"
|
||||
value={confirmPassword}
|
||||
disabled={loading}
|
||||
onChange={(e) => setConfirmPassword(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
<Button type="submit" disabled={loading}>
|
||||
Reset password
|
||||
</Button>
|
||||
</form>
|
||||
|
||||
<Button href="/sign-in" disabled={loading}>
|
||||
Sign in
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
222
examples/betterauth/src/components/forms/Settings.tsx
Normal file
@@ -0,0 +1,222 @@
|
||||
import { AccountProviders } from "@/components/AccountProviders";
|
||||
import { Button } from "@/components/Button";
|
||||
import { DeleteAccountButton } from "@/components/DeleteAccountButton";
|
||||
import { Loading } from "@/components/Loading";
|
||||
import { SSOButton } from "@/components/SSOButton";
|
||||
import { useAccount, useIsAuthenticated } from "jazz-react";
|
||||
import { useAuth } from "jazz-react-auth-betterauth";
|
||||
import type {
|
||||
AccountsType,
|
||||
FullAuthClient,
|
||||
SSOProviderType,
|
||||
} from "jazz-react-auth-betterauth";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useCallback, useEffect, useState } from "react";
|
||||
|
||||
const title = "Settings";
|
||||
|
||||
export default function SettingsForm({
|
||||
providers,
|
||||
}: {
|
||||
providers?: SSOProviderType[];
|
||||
}) {
|
||||
const router = useRouter();
|
||||
const { authClient, account, state } = useAuth();
|
||||
const hasCredentials = state !== "anonymous";
|
||||
|
||||
const [accounts, setAccounts] = useState<AccountsType | undefined>(undefined);
|
||||
useEffect(() => {
|
||||
return authClient.useSession.subscribe(() => {
|
||||
authClient.listAccounts().then((x) => setAccounts(x));
|
||||
});
|
||||
}, [authClient]);
|
||||
|
||||
const [status, setStatus] = useState<boolean>(false);
|
||||
const [loading, setLoading] = useState<boolean>(false);
|
||||
const [error, setError] = useState<Error | undefined>(undefined);
|
||||
const [otpSentStatus, setOtpSentStatus] = useState<boolean>(false);
|
||||
const [otpStatus, setOtpStatus] = useState<boolean>(false);
|
||||
const [otp, setOtp] = useState<string>("");
|
||||
|
||||
const { me, logOut } = useAccount({ resolve: { profile: true } });
|
||||
const isAuthenticated = useIsAuthenticated();
|
||||
const signOut = useCallback(() => {
|
||||
authClient
|
||||
.signOut()
|
||||
.catch(console.error)
|
||||
.finally(() => {
|
||||
logOut();
|
||||
router.push("/");
|
||||
});
|
||||
}, [logOut, authClient]);
|
||||
|
||||
return (
|
||||
<>
|
||||
<header className="absolute p-4 top-0 left-0 w-full z-10 flex items-center justify-between gap-4">
|
||||
<div className="float-start">
|
||||
{me && hasCredentials && account && isAuthenticated && (
|
||||
<Button className="float-start" onClick={signOut}>
|
||||
Sign out
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</header>
|
||||
<div className="min-h-screen flex flex-col justify-center font-[family-name:var(--font-geist-sans)]">
|
||||
<div className="max-w-md flex flex-col gap-8 w-full px-6 py-12 mx-auto">
|
||||
<h1 className="text-stone-950 dark:text-white font-display text-5xl lg:text-6xl font-medium tracking-tighter mb-2">
|
||||
{title}
|
||||
</h1>
|
||||
|
||||
{status && account && !account?.emailVerified && (
|
||||
<div>
|
||||
Instructions to verify your account have been sent to{" "}
|
||||
{account.email}, if an account with that email address exists.
|
||||
</div>
|
||||
)}
|
||||
|
||||
{(status || otpStatus) && account && account.emailVerified && (
|
||||
<div>Your account has been successfully verified.</div>
|
||||
)}
|
||||
|
||||
{error && <div>{error.message}</div>}
|
||||
|
||||
{loading && <Loading />}
|
||||
|
||||
<AccountProviders
|
||||
accounts={accounts}
|
||||
setLoading={setLoading}
|
||||
setError={setError}
|
||||
/>
|
||||
{accounts?.data &&
|
||||
providers?.map((x) => {
|
||||
return (
|
||||
accounts.data.find((y) => y.provider === x) === undefined && (
|
||||
<SSOButton
|
||||
link={true}
|
||||
provider={x}
|
||||
setLoading={setLoading}
|
||||
setError={setError}
|
||||
/>
|
||||
)
|
||||
);
|
||||
})}
|
||||
{account && account.emailVerified && <p>Account verified.</p>}
|
||||
{account && !account.emailVerified && (
|
||||
<>
|
||||
<Button
|
||||
variant="secondary"
|
||||
className="relative"
|
||||
onClick={async (e) => {
|
||||
e.preventDefault();
|
||||
setLoading(true);
|
||||
const { data, error } =
|
||||
await authClient.sendVerificationEmail({
|
||||
email: account.email,
|
||||
callbackURL: `${window.location.origin}`,
|
||||
});
|
||||
setStatus(data?.status ?? false);
|
||||
const errorMessage = error?.message ?? error?.statusText;
|
||||
setError(
|
||||
error
|
||||
? {
|
||||
...error,
|
||||
name: error.statusText,
|
||||
message:
|
||||
errorMessage && errorMessage.length > 0
|
||||
? errorMessage
|
||||
: "An error occurred",
|
||||
}
|
||||
: undefined,
|
||||
);
|
||||
setLoading(false);
|
||||
}}
|
||||
>
|
||||
Send verification link
|
||||
</Button>
|
||||
<Button
|
||||
variant="secondary"
|
||||
className="relative"
|
||||
onClick={async (e) => {
|
||||
e.preventDefault();
|
||||
setLoading(true);
|
||||
const { data, error } = await (
|
||||
authClient as FullAuthClient
|
||||
).emailOtp.sendVerificationOtp({
|
||||
email: account.email,
|
||||
type: "email-verification",
|
||||
});
|
||||
setStatus(data?.success ?? false);
|
||||
setOtpSentStatus(data?.success ?? false);
|
||||
const errorMessage = error?.message ?? error?.statusText;
|
||||
setError(
|
||||
error
|
||||
? {
|
||||
...error,
|
||||
name: error.statusText,
|
||||
message:
|
||||
errorMessage && errorMessage.length > 0
|
||||
? errorMessage
|
||||
: "An error occurred",
|
||||
}
|
||||
: undefined,
|
||||
);
|
||||
setLoading(false);
|
||||
}}
|
||||
>
|
||||
Send verification one-time password
|
||||
</Button>
|
||||
</>
|
||||
)}
|
||||
{otpSentStatus && account && !account.emailVerified && (
|
||||
<form
|
||||
className="flex flex-col gap-6"
|
||||
onSubmit={async (e) => {
|
||||
e.preventDefault();
|
||||
setLoading(true);
|
||||
const { data, error } = await (
|
||||
authClient as FullAuthClient
|
||||
).emailOtp.verifyEmail({
|
||||
email: account.email,
|
||||
otp: otp,
|
||||
});
|
||||
setOtpStatus(data?.status ?? false);
|
||||
const errorMessage = error?.message ?? error?.statusText;
|
||||
setError(
|
||||
error
|
||||
? {
|
||||
...error,
|
||||
name: error.statusText,
|
||||
message:
|
||||
errorMessage && errorMessage.length > 0
|
||||
? errorMessage
|
||||
: "An error occurred",
|
||||
}
|
||||
: undefined,
|
||||
);
|
||||
setLoading(false);
|
||||
}}
|
||||
>
|
||||
<div>
|
||||
<label htmlFor="otp">One-time password</label>
|
||||
<input
|
||||
id="otp"
|
||||
value={otp}
|
||||
disabled={loading}
|
||||
onChange={(e) => setOtp(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
<Button type={"submit"} disabled={loading}>
|
||||
Submit
|
||||
</Button>
|
||||
</form>
|
||||
)}
|
||||
<DeleteAccountButton
|
||||
setLoading={setLoading}
|
||||
setError={setError}
|
||||
callbackURL={`${window.location.origin}/delete-account`}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
245
examples/betterauth/src/components/forms/SignIn.tsx
Normal file
@@ -0,0 +1,245 @@
|
||||
import { Button } from "@/components/Button";
|
||||
import { Loading } from "@/components/Loading";
|
||||
import { SSOButton } from "@/components/SSOButton";
|
||||
import { useAuth } from "jazz-react-auth-betterauth";
|
||||
import type {
|
||||
FullAuthClient,
|
||||
SSOProviderType,
|
||||
} from "jazz-react-auth-betterauth";
|
||||
import Image from "next/image";
|
||||
import Link from "next/link";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
|
||||
const title = "Sign In";
|
||||
|
||||
export default function SignInForm({
|
||||
providers,
|
||||
}: {
|
||||
providers?: SSOProviderType[];
|
||||
}) {
|
||||
const router = useRouter();
|
||||
const auth = useAuth();
|
||||
const [email, setEmail] = useState<string>("");
|
||||
const [password, setPassword] = useState<string>("");
|
||||
const [rememberMe, setRememberMe] = useState(true);
|
||||
const [otp, setOtp] = useState<string>("");
|
||||
const [otpStatus, setOtpStatus] = useState<boolean>(false);
|
||||
const [loading, setLoading] = useState<boolean>(false);
|
||||
const [error, setError] = useState<Error | undefined>(undefined);
|
||||
|
||||
return (
|
||||
<div className="min-h-screen flex flex-col justify-center">
|
||||
<h1 className="sr-only">{title}</h1>
|
||||
<div className="max-w-md flex flex-col gap-8 w-full px-6 py-12 mx-auto">
|
||||
{otpStatus && (
|
||||
<div>A one-time password has been sent to your email.</div>
|
||||
)}
|
||||
|
||||
{error && <div>{error.message}</div>}
|
||||
|
||||
{loading && <Loading />}
|
||||
|
||||
<form
|
||||
className="flex flex-col gap-6"
|
||||
onSubmit={async (e) => {
|
||||
e.preventDefault();
|
||||
setLoading(true);
|
||||
if (!otpStatus) {
|
||||
await auth.authClient.signIn.email(
|
||||
{
|
||||
email,
|
||||
password,
|
||||
rememberMe,
|
||||
},
|
||||
{
|
||||
onSuccess: async () => {
|
||||
await auth.logIn();
|
||||
router.push("/");
|
||||
},
|
||||
onError: (error) => {
|
||||
setError(error.error);
|
||||
},
|
||||
},
|
||||
);
|
||||
} else {
|
||||
const { data, error } = await (
|
||||
auth.authClient as FullAuthClient
|
||||
).signIn.emailOtp({
|
||||
email: email,
|
||||
otp: otp,
|
||||
});
|
||||
const errorMessage = error?.message ?? error?.statusText;
|
||||
setError(
|
||||
error
|
||||
? {
|
||||
...error,
|
||||
name: error.statusText,
|
||||
message:
|
||||
errorMessage && errorMessage.length > 0
|
||||
? errorMessage
|
||||
: "An error occurred",
|
||||
}
|
||||
: undefined,
|
||||
);
|
||||
if (data) {
|
||||
await auth.logIn();
|
||||
router.push("/");
|
||||
}
|
||||
}
|
||||
setLoading(false);
|
||||
}}
|
||||
>
|
||||
<div>
|
||||
<label htmlFor="email-address">Email address</label>
|
||||
<input
|
||||
id="email-address"
|
||||
value={email}
|
||||
disabled={loading}
|
||||
onChange={(e) => setEmail(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
{!otpStatus && (
|
||||
<div>
|
||||
<label htmlFor="password">Password</label>
|
||||
<input
|
||||
id="password"
|
||||
type="password"
|
||||
value={password}
|
||||
disabled={loading}
|
||||
onChange={(e) => setPassword(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
{otpStatus && (
|
||||
<div>
|
||||
<label htmlFor="otp">One-time password</label>
|
||||
<input
|
||||
id="otp"
|
||||
value={otp}
|
||||
disabled={loading}
|
||||
onChange={(e) => setOtp(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
<div className="items-center">
|
||||
<div>
|
||||
<label htmlFor="remember-me">Remember me</label>
|
||||
<input
|
||||
id="remember-me"
|
||||
type="checkbox"
|
||||
checked={rememberMe}
|
||||
disabled={loading}
|
||||
onChange={(e) => setRememberMe(e.target.checked)}
|
||||
/>
|
||||
</div>
|
||||
<Link href="/forgot" className="text-sm float-right">
|
||||
Forgot password?
|
||||
</Link>
|
||||
</div>
|
||||
<Button type="submit" disabled={loading}>
|
||||
Sign in
|
||||
</Button>
|
||||
</form>
|
||||
|
||||
<div className="flex items-center gap-4">
|
||||
<hr className="flex-1" />
|
||||
<p className="text-center">or</p>
|
||||
<hr className="flex-1" />
|
||||
</div>
|
||||
|
||||
<div className="flex flex-col gap-4">
|
||||
{providers?.map((x) => {
|
||||
return (
|
||||
<SSOButton
|
||||
callbackURL={`${window.location.origin}/social/logIn`}
|
||||
provider={x}
|
||||
setLoading={setLoading}
|
||||
setError={setError}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
<Button
|
||||
variant="secondary"
|
||||
className="relative"
|
||||
onClick={async (e) => {
|
||||
e.preventDefault();
|
||||
setLoading(true);
|
||||
const { error } = await (
|
||||
auth.authClient as FullAuthClient
|
||||
).signIn.magicLink({
|
||||
email: email,
|
||||
callbackURL: `${window.location.origin}/magic-link/logIn`,
|
||||
});
|
||||
const errorMessage = error?.message ?? error?.statusText;
|
||||
setError(
|
||||
error
|
||||
? {
|
||||
...error,
|
||||
name: error.statusText,
|
||||
message:
|
||||
errorMessage && errorMessage.length > 0
|
||||
? errorMessage
|
||||
: "An error occurred",
|
||||
}
|
||||
: undefined,
|
||||
);
|
||||
setLoading(false);
|
||||
}}
|
||||
>
|
||||
<Image
|
||||
src="/link.svg"
|
||||
alt="Link icon"
|
||||
className="absolute left-3"
|
||||
width={16}
|
||||
height={16}
|
||||
/>
|
||||
Sign in with magic link
|
||||
</Button>
|
||||
<Button
|
||||
variant="secondary"
|
||||
className="relative"
|
||||
onClick={async (e) => {
|
||||
e.preventDefault();
|
||||
setLoading(true);
|
||||
const { data, error } = await (
|
||||
auth.authClient as FullAuthClient
|
||||
).emailOtp.sendVerificationOtp({
|
||||
email: email,
|
||||
type: "sign-in",
|
||||
});
|
||||
setOtpStatus(data?.success ?? false);
|
||||
const errorMessage = error?.message ?? error?.statusText;
|
||||
setError(
|
||||
error
|
||||
? {
|
||||
...error,
|
||||
name: error.statusText,
|
||||
message:
|
||||
errorMessage && errorMessage.length > 0
|
||||
? errorMessage
|
||||
: "An error occurred",
|
||||
}
|
||||
: undefined,
|
||||
);
|
||||
setLoading(false);
|
||||
}}
|
||||
>
|
||||
<Image
|
||||
src="/mail.svg"
|
||||
alt="Mail icon"
|
||||
className="absolute left-3"
|
||||
width={16}
|
||||
height={16}
|
||||
/>
|
||||
Sign in with one-time password
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<p className="text-sm">
|
||||
Don't have an account? <Link href="/sign-up">Sign up</Link>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
257
examples/betterauth/src/components/forms/SignUp.tsx
Normal file
@@ -0,0 +1,257 @@
|
||||
import { Button } from "@/components/Button";
|
||||
import { Loading } from "@/components/Loading";
|
||||
import { SSOButton } from "@/components/SSOButton";
|
||||
import { useAuth } from "jazz-react-auth-betterauth";
|
||||
import type {
|
||||
FullAuthClient,
|
||||
SSOProviderType,
|
||||
} from "jazz-react-auth-betterauth";
|
||||
import Image from "next/image";
|
||||
import Link from "next/link";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
|
||||
const title = "Sign Up";
|
||||
|
||||
export default function SignUpForm({
|
||||
providers,
|
||||
}: {
|
||||
providers?: SSOProviderType[];
|
||||
}) {
|
||||
const router = useRouter();
|
||||
const auth = useAuth();
|
||||
const [name, setName] = useState<string>("");
|
||||
const [email, setEmail] = useState<string>("");
|
||||
const [password, setPassword] = useState<string>("");
|
||||
const [confirmPassword, setConfirmPassword] = useState<string>("");
|
||||
const [otp, setOtp] = useState<string>("");
|
||||
const [otpStatus, setOtpStatus] = useState<boolean>(false);
|
||||
const [loading, setLoading] = useState<boolean>(false);
|
||||
const [error, setError] = useState<Error | undefined>(undefined);
|
||||
|
||||
return (
|
||||
<div className="min-h-screen flex flex-col justify-center">
|
||||
<h1 className="sr-only">{title}</h1>
|
||||
<div className="max-w-md flex flex-col gap-8 w-full px-6 py-12 mx-auto">
|
||||
{otpStatus && (
|
||||
<div>A one-time password has been sent to your email.</div>
|
||||
)}
|
||||
|
||||
{error && <div>{error.message}</div>}
|
||||
|
||||
{loading && <Loading />}
|
||||
|
||||
<form
|
||||
className="flex flex-col gap-6"
|
||||
onSubmit={async (e) => {
|
||||
e.preventDefault();
|
||||
setLoading(true);
|
||||
if (password !== confirmPassword) {
|
||||
setError(new Error("Passwords do not match"));
|
||||
setLoading(false);
|
||||
return;
|
||||
}
|
||||
if (!otpStatus) {
|
||||
await auth.authClient.signUp.email(
|
||||
{
|
||||
email,
|
||||
password,
|
||||
name,
|
||||
},
|
||||
{
|
||||
onSuccess: async () => {
|
||||
await auth.signIn();
|
||||
router.push("/");
|
||||
},
|
||||
onError: (error) => {
|
||||
setError(error.error);
|
||||
},
|
||||
},
|
||||
);
|
||||
} else {
|
||||
const { data, error } = await (
|
||||
auth.authClient as FullAuthClient
|
||||
).signIn.emailOtp({
|
||||
email: email,
|
||||
otp: otp,
|
||||
});
|
||||
const errorMessage = error?.message ?? error?.statusText;
|
||||
setError(
|
||||
error
|
||||
? {
|
||||
...error,
|
||||
name: error.statusText,
|
||||
message:
|
||||
errorMessage && errorMessage.length > 0
|
||||
? errorMessage
|
||||
: "An error occurred",
|
||||
}
|
||||
: undefined,
|
||||
);
|
||||
if (data) {
|
||||
await auth.signIn();
|
||||
router.push("/");
|
||||
}
|
||||
}
|
||||
setLoading(false);
|
||||
}}
|
||||
>
|
||||
<div>
|
||||
<label htmlFor="full-name">Full name</label>
|
||||
<input
|
||||
id="full-name"
|
||||
value={name}
|
||||
disabled={loading}
|
||||
onChange={(e) => setName(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label htmlFor="email-address">Email address</label>
|
||||
<input
|
||||
id="email-address"
|
||||
value={email}
|
||||
disabled={loading}
|
||||
onChange={(e) => setEmail(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
{!otpStatus && (
|
||||
<>
|
||||
<div>
|
||||
<label htmlFor="password">Password</label>
|
||||
<input
|
||||
id="password"
|
||||
type="password"
|
||||
value={password}
|
||||
disabled={loading}
|
||||
onChange={(e) => setPassword(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label htmlFor="confirm-password">Confirm password</label>
|
||||
<input
|
||||
id="confirm-password"
|
||||
type="password"
|
||||
value={confirmPassword}
|
||||
disabled={loading}
|
||||
onChange={(e) => setConfirmPassword(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
{otpStatus && (
|
||||
<div>
|
||||
<label htmlFor="otp">One-time password</label>
|
||||
<input
|
||||
id="otp"
|
||||
value={otp}
|
||||
disabled={loading}
|
||||
onChange={(e) => setOtp(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
<Button type="submit" disabled={loading}>
|
||||
Sign up
|
||||
</Button>
|
||||
</form>
|
||||
|
||||
<div className="flex items-center gap-4">
|
||||
<hr className="flex-1" />
|
||||
<p className="text-center">or</p>
|
||||
<hr className="flex-1" />
|
||||
</div>
|
||||
|
||||
<div className="flex flex-col gap-4">
|
||||
{providers?.map((x) => {
|
||||
return (
|
||||
<SSOButton
|
||||
callbackURL={`${window.location.origin}/social/signIn`}
|
||||
provider={x}
|
||||
setLoading={setLoading}
|
||||
setError={setError}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
<Button
|
||||
variant="secondary"
|
||||
className="relative"
|
||||
onClick={async (e) => {
|
||||
e.preventDefault();
|
||||
setLoading(true);
|
||||
const { error } = await (
|
||||
auth.authClient as FullAuthClient
|
||||
).signIn.magicLink({
|
||||
email: email,
|
||||
callbackURL: `${window.location.origin}/magic-link/signIn`,
|
||||
});
|
||||
const errorMessage = error?.message ?? error?.statusText;
|
||||
setError(
|
||||
error
|
||||
? {
|
||||
...error,
|
||||
name: error.statusText,
|
||||
message:
|
||||
errorMessage && errorMessage.length > 0
|
||||
? errorMessage
|
||||
: "An error occurred",
|
||||
}
|
||||
: undefined,
|
||||
);
|
||||
setLoading(false);
|
||||
}}
|
||||
>
|
||||
<Image
|
||||
src="/link.svg"
|
||||
alt="Link icon"
|
||||
className="absolute left-3"
|
||||
width={16}
|
||||
height={16}
|
||||
/>
|
||||
Sign up with magic link
|
||||
</Button>
|
||||
<Button
|
||||
variant="secondary"
|
||||
className="relative"
|
||||
onClick={async (e) => {
|
||||
e.preventDefault();
|
||||
setLoading(true);
|
||||
const { data, error } = await (
|
||||
auth.authClient as FullAuthClient
|
||||
).emailOtp.sendVerificationOtp({
|
||||
email: email,
|
||||
type: "sign-in",
|
||||
});
|
||||
setOtpStatus(data?.success ?? false);
|
||||
const errorMessage = error?.message ?? error?.statusText;
|
||||
setError(
|
||||
error
|
||||
? {
|
||||
...error,
|
||||
name: error.statusText,
|
||||
message:
|
||||
errorMessage && errorMessage.length > 0
|
||||
? errorMessage
|
||||
: "An error occurred",
|
||||
}
|
||||
: undefined,
|
||||
);
|
||||
setLoading(false);
|
||||
}}
|
||||
>
|
||||
<Image
|
||||
src="/mail.svg"
|
||||
alt="Mail icon"
|
||||
className="absolute left-3"
|
||||
width={16}
|
||||
height={16}
|
||||
/>
|
||||
Sign up with one-time password
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<p className="text-sm">
|
||||
Already have an account? <Link href="/sign-in">Sign in</Link>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import { useAuth } from "jazz-react-auth-betterauth";
|
||||
import { useRouter } from "next/navigation";
|
||||
|
||||
export default function Page() {
|
||||
const router = useRouter();
|
||||
const auth = useAuth();
|
||||
const searchParams = new URLSearchParams(window.location.search);
|
||||
const error = searchParams.get("error");
|
||||
if (!error) {
|
||||
auth.logIn().then(() => router.push("/"));
|
||||
return null;
|
||||
} else {
|
||||
return (
|
||||
<div className="min-h-screen flex flex-col justify-center">
|
||||
<div className="max-w-md flex flex-col gap-8 w-full px-6 py-12 mx-auto">
|
||||
<div>{error}</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import { useAuth } from "jazz-react-auth-betterauth";
|
||||
import { useRouter } from "next/navigation";
|
||||
|
||||
export default function Page() {
|
||||
const router = useRouter();
|
||||
const auth = useAuth();
|
||||
const searchParams = new URLSearchParams(window.location.search);
|
||||
const error = searchParams.get("error");
|
||||
if (!error) {
|
||||
auth.signIn().then(() => router.push("/"));
|
||||
return null;
|
||||
} else {
|
||||
return (
|
||||
<div className="min-h-screen flex flex-col justify-center">
|
||||
<div className="max-w-md flex flex-col gap-8 w-full px-6 py-12 mx-auto">
|
||||
<div>{error}</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
63
examples/betterauth/src/lib/auth-email.ts
Normal file
@@ -0,0 +1,63 @@
|
||||
import type { betterAuth } from "better-auth";
|
||||
import type { emailOTP } from "better-auth/plugins";
|
||||
import type { magicLink } from "better-auth/plugins";
|
||||
|
||||
export const sendEmailOtpCb: Parameters<
|
||||
typeof emailOTP
|
||||
>[0]["sendVerificationOTP"] = async ({ email, otp, type }) => {
|
||||
const searchParams = new URLSearchParams();
|
||||
searchParams.set("email", email);
|
||||
searchParams.set("otp", otp);
|
||||
|
||||
let emailLink = "";
|
||||
if (type === "sign-in") {
|
||||
// Send the OTP for sign-in
|
||||
emailLink = `/mockEmail/sign-in?${searchParams.toString()}`;
|
||||
} else if (type === "email-verification") {
|
||||
// Send the OTP for email verification
|
||||
emailLink = `/mockEmail/email-verification?${searchParams.toString()}`;
|
||||
} else {
|
||||
// Send the OTP for password reset
|
||||
emailLink = `/mockEmail/forget-password?${searchParams.toString()}`;
|
||||
}
|
||||
console.log("Mock email sent: " + emailLink);
|
||||
};
|
||||
|
||||
export const sendMagicLinkCb: Parameters<typeof magicLink>[0]["sendMagicLink"] =
|
||||
async ({ email, url }) => {
|
||||
const searchParams = new URLSearchParams();
|
||||
searchParams.set("url", url);
|
||||
const emailLink = `/mockEmail/sign-in?${searchParams.toString()}`;
|
||||
console.log("Mock email sent: " + emailLink);
|
||||
};
|
||||
|
||||
export const sendWelcomeEmailCb: NonNullable<
|
||||
NonNullable<
|
||||
NonNullable<Parameters<typeof betterAuth>[0]["databaseHooks"]>["user"]
|
||||
>["create"]
|
||||
>["after"] = async (user) => {
|
||||
const searchParams = new URLSearchParams();
|
||||
searchParams.set("name", user.name);
|
||||
const emailLink = `/mockEmail/welcome?${searchParams.toString()}`;
|
||||
console.log("Mock email sent: " + emailLink);
|
||||
};
|
||||
|
||||
export const sendVerificationEmailCb: NonNullable<
|
||||
Parameters<typeof betterAuth>[0]["emailVerification"]
|
||||
>["sendVerificationEmail"] = async ({ user, url }) => {
|
||||
const searchParams = new URLSearchParams();
|
||||
searchParams.set("name", user.name);
|
||||
searchParams.set("url", url);
|
||||
const emailLink = `/mockEmail/email-verification?${searchParams.toString()}`;
|
||||
console.log("Mock email sent: " + emailLink);
|
||||
};
|
||||
|
||||
export const sendResetPasswordCb: NonNullable<
|
||||
Parameters<typeof betterAuth>[0]["emailAndPassword"]
|
||||
>["sendResetPassword"] = async ({ user, url }) => {
|
||||
const searchParams = new URLSearchParams();
|
||||
searchParams.set("name", user.name);
|
||||
searchParams.set("url", url);
|
||||
const emailLink = `/mockEmail/forgot-password?${searchParams.toString()}`;
|
||||
console.log("Mock email sent: " + emailLink);
|
||||
};
|
||||
62
examples/betterauth/src/lib/auth.ts
Normal file
@@ -0,0 +1,62 @@
|
||||
import { appName } from "@/components/emails";
|
||||
import { betterAuth } from "better-auth";
|
||||
import { getMigrations } from "better-auth/db";
|
||||
import { emailOTP, haveIBeenPwned, magicLink } from "better-auth/plugins";
|
||||
import Database from "better-sqlite3";
|
||||
import { jazzPlugin } from "jazz-betterauth-server-plugin";
|
||||
import {
|
||||
sendEmailOtpCb,
|
||||
sendMagicLinkCb,
|
||||
sendResetPasswordCb,
|
||||
sendVerificationEmailCb,
|
||||
sendWelcomeEmailCb,
|
||||
} from "./auth-email";
|
||||
import { socialProviders } from "./socialProviders";
|
||||
|
||||
export const auth = await (async () => {
|
||||
// Configure Better Auth server
|
||||
const auth = betterAuth({
|
||||
appName: appName,
|
||||
database: new Database("sqlite.db"),
|
||||
emailAndPassword: {
|
||||
enabled: true,
|
||||
sendResetPassword: sendResetPasswordCb,
|
||||
},
|
||||
emailVerification: {
|
||||
sendVerificationEmail: sendVerificationEmailCb,
|
||||
},
|
||||
socialProviders: socialProviders,
|
||||
account: {
|
||||
accountLinking: {
|
||||
allowDifferentEmails: true,
|
||||
allowUnlinkingAll: true,
|
||||
},
|
||||
},
|
||||
user: {
|
||||
deleteUser: {
|
||||
enabled: true,
|
||||
},
|
||||
},
|
||||
plugins: [
|
||||
haveIBeenPwned(),
|
||||
jazzPlugin(),
|
||||
magicLink({
|
||||
sendMagicLink: sendMagicLinkCb,
|
||||
}),
|
||||
emailOTP({ sendVerificationOTP: sendEmailOtpCb }),
|
||||
],
|
||||
databaseHooks: {
|
||||
user: {
|
||||
create: {
|
||||
after: sendWelcomeEmailCb,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
// Run database migrations
|
||||
const migrations = await getMigrations(auth.options);
|
||||
await migrations.runMigrations();
|
||||
|
||||
return auth;
|
||||
})();
|
||||
186
examples/betterauth/src/lib/socialProviders.ts
Normal file
@@ -0,0 +1,186 @@
|
||||
const apple =
|
||||
process.env.APPLE_CLIENT_ID &&
|
||||
process.env.APPLE_CLIENT_SECRET &&
|
||||
process.env.APPLE_APP_BUNDLE_IDENTIFIER
|
||||
? {
|
||||
apple: {
|
||||
clientId: process.env.APPLE_CLIENT_ID as string,
|
||||
clientSecret: process.env.APPLE_CLIENT_SECRET as string,
|
||||
// For native iOS
|
||||
appBundleIdentifier: process.env
|
||||
.APPLE_APP_BUNDLE_IDENTIFIER as string,
|
||||
},
|
||||
}
|
||||
: undefined;
|
||||
const discord =
|
||||
process.env.DISCORD_CLIENT_ID && process.env.DISCORD_CLIENT_SECRET
|
||||
? {
|
||||
discord: {
|
||||
clientId: process.env.DISCORD_CLIENT_ID as string,
|
||||
clientSecret: process.env.DISCORD_CLIENT_SECRET as string,
|
||||
},
|
||||
}
|
||||
: undefined;
|
||||
const facebook =
|
||||
process.env.FACEBOOK_CLIENT_ID && process.env.FACEBOOK_CLIENT_SECRET
|
||||
? {
|
||||
facebook: {
|
||||
clientId: process.env.FACEBOOK_CLIENT_ID as string,
|
||||
clientSecret: process.env.FACEBOOK_CLIENT_SECRET as string,
|
||||
},
|
||||
}
|
||||
: undefined;
|
||||
const github =
|
||||
process.env.GITHUB_CLIENT_ID && process.env.GITHUB_CLIENT_SECRET
|
||||
? {
|
||||
github: {
|
||||
clientId: process.env.GITHUB_CLIENT_ID as string,
|
||||
clientSecret: process.env.GITHUB_CLIENT_SECRET as string,
|
||||
},
|
||||
}
|
||||
: undefined;
|
||||
const google =
|
||||
process.env.GOOGLE_CLIENT_ID && process.env.GOOGLE_CLIENT_SECRET
|
||||
? {
|
||||
google: {
|
||||
clientId: process.env.GOOGLE_CLIENT_ID as string,
|
||||
clientSecret: process.env.GOOGLE_CLIENT_SECRET as string,
|
||||
},
|
||||
}
|
||||
: undefined;
|
||||
const kick =
|
||||
process.env.KICK_CLIENT_ID && process.env.KICK_CLIENT_SECRET
|
||||
? {
|
||||
kick: {
|
||||
clientId: process.env.KICK_CLIENT_ID as string,
|
||||
clientSecret: process.env.KICK_CLIENT_SECRET as string,
|
||||
},
|
||||
}
|
||||
: undefined;
|
||||
const microsoft =
|
||||
process.env.MICROSOFT_CLIENT_ID && process.env.MICROSOFT_CLIENT_SECRET
|
||||
? {
|
||||
microsoft: {
|
||||
clientId: process.env.MICROSOFT_CLIENT_ID as string,
|
||||
clientSecret: process.env.MICROSOFT_CLIENT_SECRET as string,
|
||||
tenantId: "common",
|
||||
requireSelectAccount: true,
|
||||
},
|
||||
}
|
||||
: undefined;
|
||||
const tiktok =
|
||||
process.env.TIKTOK_CLIENT_ID &&
|
||||
process.env.TIKTOK_CLIENT_SECRET &&
|
||||
process.env.TIKTOK_CLIENT_KEY
|
||||
? {
|
||||
tiktok: {
|
||||
clientId: process.env.TIKTOK_CLIENT_ID,
|
||||
clientSecret: process.env.TIKTOK_CLIENT_SECRET,
|
||||
clientKey: process.env.TIKTOK_CLIENT_KEY,
|
||||
},
|
||||
}
|
||||
: undefined;
|
||||
const twitch =
|
||||
process.env.TWITCH_CLIENT_ID && process.env.TWITCH_CLIENT_SECRET
|
||||
? {
|
||||
twitch: {
|
||||
clientId: process.env.TWITCH_CLIENT_ID as string,
|
||||
clientSecret: process.env.TWITCH_CLIENT_SECRET as string,
|
||||
},
|
||||
}
|
||||
: undefined;
|
||||
const twitter =
|
||||
process.env.TWITTER_CLIENT_ID && process.env.TWITTER_CLIENT_SECRET
|
||||
? {
|
||||
twitter: {
|
||||
clientId: process.env.TWITTER_CLIENT_ID,
|
||||
clientSecret: process.env.TWITTER_CLIENT_SECRET,
|
||||
},
|
||||
}
|
||||
: undefined;
|
||||
const dropbox =
|
||||
process.env.DROPBOX_CLIENT_ID && process.env.DROPBOX_CLIENT_SECRET
|
||||
? {
|
||||
dropbox: {
|
||||
clientId: process.env.DROPBOX_CLIENT_ID as string,
|
||||
clientSecret: process.env.DROPBOX_CLIENT_SECRET as string,
|
||||
},
|
||||
}
|
||||
: undefined;
|
||||
const linkedin =
|
||||
process.env.LINKEDIN_CLIENT_ID && process.env.LINKEDIN_CLIENT_SECRET
|
||||
? {
|
||||
linkedin: {
|
||||
clientId: process.env.LINKEDIN_CLIENT_ID as string,
|
||||
clientSecret: process.env.LINKEDIN_CLIENT_SECRET as string,
|
||||
},
|
||||
}
|
||||
: undefined;
|
||||
const gitlab =
|
||||
process.env.GITLAB_CLIENT_ID &&
|
||||
process.env.GITLAB_CLIENT_SECRET &&
|
||||
process.env.GITLAB_ISSUER
|
||||
? {
|
||||
gitlab: {
|
||||
clientId: process.env.GITLAB_CLIENT_ID as string,
|
||||
clientSecret: process.env.GITLAB_CLIENT_SECRET as string,
|
||||
issuer: process.env.GITLAB_ISSUER as string,
|
||||
},
|
||||
}
|
||||
: undefined;
|
||||
const reddit =
|
||||
process.env.REDDIT_CLIENT_ID && process.env.REDDIT_CLIENT_SECRET
|
||||
? {
|
||||
reddit: {
|
||||
clientId: process.env.REDDIT_CLIENT_ID as string,
|
||||
clientSecret: process.env.REDDIT_CLIENT_SECRET as string,
|
||||
},
|
||||
}
|
||||
: undefined;
|
||||
const roblox =
|
||||
process.env.ROBLOX_CLIENT_ID && process.env.ROBLOX_CLIENT_SECRET
|
||||
? {
|
||||
roblox: {
|
||||
clientId: process.env.ROBLOX_CLIENT_ID,
|
||||
clientSecret: process.env.ROBLOX_CLIENT_SECRET,
|
||||
},
|
||||
}
|
||||
: undefined;
|
||||
const spotify =
|
||||
process.env.SPOTIFY_CLIENT_ID && process.env.SPOTIFY_CLIENT_SECRET
|
||||
? {
|
||||
spotify: {
|
||||
clientId: process.env.SPOTIFY_CLIENT_ID as string,
|
||||
clientSecret: process.env.SPOTIFY_CLIENT_SECRET as string,
|
||||
},
|
||||
}
|
||||
: undefined;
|
||||
const vk =
|
||||
process.env.VK_CLIENT_ID && process.env.VK_CLIENT_SECRET
|
||||
? {
|
||||
vk: {
|
||||
clientId: process.env.VK_CLIENT_ID as string,
|
||||
clientSecret: process.env.VK_CLIENT_SECRET as string,
|
||||
},
|
||||
}
|
||||
: undefined;
|
||||
|
||||
export const socialProviders = {
|
||||
...(apple && { ...apple }),
|
||||
...(discord && { ...discord }),
|
||||
...(facebook && { ...facebook }),
|
||||
...(github && { ...github }),
|
||||
...(google && { ...google }),
|
||||
...(kick && { ...kick }),
|
||||
...(microsoft && { ...microsoft }),
|
||||
...(tiktok && { ...tiktok }),
|
||||
...(twitch && { ...twitch }),
|
||||
...(twitter && { ...twitter }),
|
||||
...(dropbox && { ...dropbox }),
|
||||
...(linkedin && { ...linkedin }),
|
||||
...(gitlab && { ...gitlab }),
|
||||
...(reddit && { ...reddit }),
|
||||
...(roblox && { ...roblox }),
|
||||
...(spotify && { ...spotify }),
|
||||
...(vk && { ...vk }),
|
||||
};
|
||||
28
examples/betterauth/tests/authFlow.spec.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { randomBytes } from "node:crypto";
|
||||
import { test } from "@playwright/test";
|
||||
import { HomePage } from "./pages/HomePage";
|
||||
|
||||
test("should sign up, sign in, and logout", async ({ page }) => {
|
||||
const username = randomBytes(4).toString("hex");
|
||||
const email = `${username}@example.com`;
|
||||
const password = randomBytes(8).toString("hex");
|
||||
|
||||
// Sign up
|
||||
await page.goto("/");
|
||||
const homePage = new HomePage(page);
|
||||
await homePage.expectLoggedOut();
|
||||
await homePage.signUpLinkButton.click();
|
||||
await homePage.signUpEmail(username, email, password);
|
||||
await homePage.expectLoggedIn(username);
|
||||
|
||||
// Log out & sign in
|
||||
await homePage.logout();
|
||||
await homePage.expectLoggedOut();
|
||||
await homePage.signInLinkButton.click();
|
||||
await homePage.signInEmail(email, password);
|
||||
await homePage.expectLoggedIn(username);
|
||||
|
||||
// Logout
|
||||
await homePage.logout();
|
||||
await homePage.expectLoggedOut();
|
||||
});
|
||||
76
examples/betterauth/tests/pages/HomePage.ts
Normal file
@@ -0,0 +1,76 @@
|
||||
import { type Page, expect } from "@playwright/test";
|
||||
|
||||
export class HomePage {
|
||||
constructor(public page: Page) {}
|
||||
|
||||
usernameInput = this.page.getByRole("textbox", {
|
||||
name: "Full name",
|
||||
exact: true,
|
||||
});
|
||||
emailInput = this.page.getByRole("textbox", {
|
||||
name: "Email address",
|
||||
exact: true,
|
||||
});
|
||||
passwordInput = this.page.getByRole("textbox", {
|
||||
name: "Password",
|
||||
exact: true,
|
||||
});
|
||||
confirmPasswordInput = this.page.getByRole("textbox", {
|
||||
name: "Confirm password",
|
||||
exact: true,
|
||||
});
|
||||
signUpButton = this.page.getByRole("button", {
|
||||
name: "Sign up",
|
||||
exact: true,
|
||||
});
|
||||
signInButton = this.page.getByRole("button", {
|
||||
name: "Sign in",
|
||||
exact: true,
|
||||
});
|
||||
signUpLinkButton = this.page.getByRole("link", {
|
||||
name: "Sign up",
|
||||
exact: true,
|
||||
});
|
||||
signInLinkButton = this.page.getByRole("link", {
|
||||
name: "Sign in",
|
||||
exact: true,
|
||||
});
|
||||
logoutButton = this.page.getByRole("button", {
|
||||
name: "Sign out",
|
||||
exact: true,
|
||||
});
|
||||
|
||||
async signUpEmail(name: string, email: string, password: string) {
|
||||
await this.usernameInput.fill(name);
|
||||
await this.emailInput.fill(email);
|
||||
await this.passwordInput.fill(password);
|
||||
await this.confirmPasswordInput.fill(password);
|
||||
await this.signUpButton.click();
|
||||
}
|
||||
|
||||
async signInEmail(email: string, password: string) {
|
||||
await this.emailInput.fill(email);
|
||||
await this.passwordInput.fill(password);
|
||||
await this.signInButton.click();
|
||||
}
|
||||
|
||||
async logout() {
|
||||
await this.logoutButton.click();
|
||||
}
|
||||
|
||||
async expectLoggedIn(name?: string) {
|
||||
await expect(this.logoutButton).toBeVisible();
|
||||
await expect(this.signInLinkButton).not.toBeVisible();
|
||||
await expect(this.signUpLinkButton).not.toBeVisible();
|
||||
if (name) {
|
||||
await expect(this.page.getByText(`Signed in as ${name}.`)).toBeVisible();
|
||||
}
|
||||
}
|
||||
|
||||
async expectLoggedOut() {
|
||||
await expect(this.logoutButton).not.toBeVisible();
|
||||
await expect(this.signInLinkButton).toBeVisible();
|
||||
await expect(this.signUpLinkButton).toBeVisible();
|
||||
await expect(this.page.getByText(`Not signed in.`)).toBeVisible();
|
||||
}
|
||||
}
|
||||
27
examples/betterauth/tsconfig.json
Normal file
@@ -0,0 +1,27 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES2017",
|
||||
"lib": ["dom", "dom.iterable", "esnext"],
|
||||
"allowJs": true,
|
||||
"skipLibCheck": true,
|
||||
"strict": true,
|
||||
"noEmit": true,
|
||||
"esModuleInterop": true,
|
||||
"module": "esnext",
|
||||
"moduleResolution": "bundler",
|
||||
"resolveJsonModule": true,
|
||||
"isolatedModules": true,
|
||||
"jsx": "preserve",
|
||||
"incremental": true,
|
||||
"plugins": [
|
||||
{
|
||||
"name": "next"
|
||||
}
|
||||
],
|
||||
"paths": {
|
||||
"@/*": ["./src/*"]
|
||||
}
|
||||
},
|
||||
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
|
||||
"exclude": ["node_modules"]
|
||||
}
|
||||
@@ -1,5 +1,46 @@
|
||||
# chat-rn-expo-clerk
|
||||
|
||||
## 1.0.120
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-expo@0.13.29
|
||||
- jazz-tools@0.13.29
|
||||
- jazz-react-native-media-images@0.13.29
|
||||
|
||||
## 1.0.119
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-expo@0.13.28
|
||||
- jazz-tools@0.13.28
|
||||
- jazz-react-native-media-images@0.13.28
|
||||
|
||||
## 1.0.118
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-expo@0.13.27
|
||||
- jazz-tools@0.13.27
|
||||
- jazz-react-native-media-images@0.13.27
|
||||
|
||||
## 1.0.117
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [ff846d9]
|
||||
- jazz-tools@0.13.26
|
||||
- jazz-expo@0.13.26
|
||||
- jazz-react-native-media-images@0.13.26
|
||||
|
||||
## 1.0.116
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-expo@0.13.25
|
||||
- jazz-tools@0.13.25
|
||||
- jazz-react-native-media-images@0.13.25
|
||||
|
||||
## 1.0.115
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -7,7 +7,7 @@ import { useLocalSearchParams } from "expo-router";
|
||||
import { useAccount, useCoState } from "jazz-expo";
|
||||
import { ProgressiveImg } from "jazz-expo";
|
||||
import { createImage } from "jazz-react-native-media-images";
|
||||
import { Group, ID } from "jazz-tools";
|
||||
import { CoPlainText, Group, ID } from "jazz-tools";
|
||||
import { useEffect, useLayoutEffect, useState } from "react";
|
||||
import React, {
|
||||
SafeAreaView,
|
||||
@@ -71,8 +71,8 @@ export default function Conversation() {
|
||||
|
||||
const loadChat = async (chatId: ID<Chat>) => {
|
||||
try {
|
||||
const chat = await Chat.load(chatId, me);
|
||||
setChat(chat);
|
||||
const chat = await Chat.load(chatId);
|
||||
if (chat) setChat(chat);
|
||||
} catch (error) {
|
||||
console.log("Error loading chat", error);
|
||||
Alert.alert("Error", `Error loading chat: ${error}`);
|
||||
@@ -82,7 +82,12 @@ export default function Conversation() {
|
||||
const sendMessage = () => {
|
||||
if (!chat) return;
|
||||
if (message.trim()) {
|
||||
chat.push(Message.create({ text: message }, { owner: chat._owner }));
|
||||
chat.push(
|
||||
Message.create(
|
||||
{ text: CoPlainText.create(message, chat._owner) },
|
||||
chat._owner,
|
||||
),
|
||||
);
|
||||
setMessage("");
|
||||
}
|
||||
};
|
||||
@@ -104,7 +109,12 @@ export default function Conversation() {
|
||||
maxSize: 2048,
|
||||
});
|
||||
|
||||
chat.push(Message.create({ text: "", image }, { owner: chat._owner }));
|
||||
chat.push(
|
||||
Message.create(
|
||||
{ text: CoPlainText.create("", chat._owner), image },
|
||||
chat._owner,
|
||||
),
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
Alert.alert("Error", "Failed to upload image");
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "chat-rn-expo-clerk",
|
||||
"main": "index.js",
|
||||
"version": "1.0.115",
|
||||
"version": "1.0.120",
|
||||
"scripts": {
|
||||
"build": "expo export -p ios",
|
||||
"start": "expo start",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { CoList, CoMap, ImageDefinition, co } from "jazz-tools";
|
||||
import { CoList, CoMap, CoPlainText, ImageDefinition, co } from "jazz-tools";
|
||||
|
||||
export class Message extends CoMap {
|
||||
text = co.string;
|
||||
text = co.ref(CoPlainText);
|
||||
image = co.optional.ref(ImageDefinition);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,41 @@
|
||||
# chat-rn-expo
|
||||
|
||||
## 1.0.107
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-expo@0.13.29
|
||||
- jazz-tools@0.13.29
|
||||
|
||||
## 1.0.106
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-expo@0.13.28
|
||||
- jazz-tools@0.13.28
|
||||
|
||||
## 1.0.105
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-expo@0.13.27
|
||||
- jazz-tools@0.13.27
|
||||
|
||||
## 1.0.104
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [ff846d9]
|
||||
- jazz-tools@0.13.26
|
||||
- jazz-expo@0.13.26
|
||||
|
||||
## 1.0.103
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-expo@0.13.25
|
||||
- jazz-tools@0.13.25
|
||||
|
||||
## 1.0.102
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "chat-rn-expo",
|
||||
"version": "1.0.102",
|
||||
"version": "1.0.107",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"build": "expo export -p ios",
|
||||
|
||||
@@ -1,5 +1,56 @@
|
||||
# chat-rn
|
||||
|
||||
## 1.0.115
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [eef1a5d]
|
||||
- Updated dependencies [191ae38]
|
||||
- Updated dependencies [daee7b9]
|
||||
- cojson@0.13.29
|
||||
- jazz-react-native@0.13.29
|
||||
- cojson-transport-ws@0.13.29
|
||||
- jazz-tools@0.13.29
|
||||
|
||||
## 1.0.114
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [e7ccb2c]
|
||||
- Updated dependencies [422dbc4]
|
||||
- cojson@0.13.28
|
||||
- cojson-transport-ws@0.13.28
|
||||
- jazz-react-native@0.13.28
|
||||
- jazz-tools@0.13.28
|
||||
|
||||
## 1.0.113
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [6357052]
|
||||
- cojson@0.13.27
|
||||
- cojson-transport-ws@0.13.27
|
||||
- jazz-react-native@0.13.27
|
||||
- jazz-tools@0.13.27
|
||||
|
||||
## 1.0.112
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [ff846d9]
|
||||
- jazz-tools@0.13.26
|
||||
- jazz-react-native@0.13.26
|
||||
|
||||
## 1.0.111
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [a846e07]
|
||||
- cojson@0.13.25
|
||||
- cojson-transport-ws@0.13.25
|
||||
- jazz-react-native@0.13.25
|
||||
- jazz-tools@0.13.25
|
||||
|
||||
## 1.0.110
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "chat-rn",
|
||||
"version": "1.0.110",
|
||||
"version": "1.0.115",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"android": "react-native run-android",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import Clipboard from "@react-native-clipboard/clipboard";
|
||||
import { useAccount, useCoState } from "jazz-react-native";
|
||||
import { Group, ID, Profile } from "jazz-tools";
|
||||
import { CoPlainText, Group, ID, Profile } from "jazz-tools";
|
||||
import { useEffect, useState } from "react";
|
||||
import {
|
||||
Alert,
|
||||
@@ -83,7 +83,10 @@ export function ChatScreen({ navigation }: { navigation: any }) {
|
||||
if (!loadedChat) return;
|
||||
if (message.trim()) {
|
||||
loadedChat.push(
|
||||
Message.create({ text: message }, { owner: loadedChat?._owner }),
|
||||
Message.create(
|
||||
{ text: CoPlainText.create(message, loadedChat?._owner) },
|
||||
loadedChat?._owner,
|
||||
),
|
||||
);
|
||||
setMessage("");
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { CoList, CoMap, co } from "jazz-tools";
|
||||
import { CoList, CoMap, CoPlainText, co } from "jazz-tools";
|
||||
|
||||
export class Message extends CoMap {
|
||||
text = co.string;
|
||||
text = co.ref(CoPlainText);
|
||||
}
|
||||
|
||||
export class Chat extends CoList.Of(co.ref(Message)) {}
|
||||
|
||||
@@ -1,5 +1,46 @@
|
||||
# chat-vue
|
||||
|
||||
## 0.0.98
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-browser@0.13.29
|
||||
- jazz-tools@0.13.29
|
||||
- jazz-vue@0.13.29
|
||||
|
||||
## 0.0.97
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-browser@0.13.28
|
||||
- jazz-tools@0.13.28
|
||||
- jazz-vue@0.13.28
|
||||
|
||||
## 0.0.96
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-browser@0.13.27
|
||||
- jazz-tools@0.13.27
|
||||
- jazz-vue@0.13.27
|
||||
|
||||
## 0.0.95
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [ff846d9]
|
||||
- jazz-tools@0.13.26
|
||||
- jazz-browser@0.13.26
|
||||
- jazz-vue@0.13.26
|
||||
|
||||
## 0.0.94
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-browser@0.13.25
|
||||
- jazz-tools@0.13.25
|
||||
- jazz-vue@0.13.25
|
||||
|
||||
## 0.0.93
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
{
|
||||
"name": "chat-vue",
|
||||
"version": "0.0.93",
|
||||
"version": "0.0.98",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build-type-check": "run-p type-check \"build-only {@}\" --",
|
||||
"build-type-check": "run-p type-check \"build {@}\" --",
|
||||
"preview": "vite preview",
|
||||
"build": "vite build",
|
||||
"type-check": "vue-tsc --build --force",
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
<template>
|
||||
<BubbleContainer :fromMe="lastEdit.by?.isMe">
|
||||
<BubbleBody>{{ msg.text }}</BubbleBody>
|
||||
<BubbleInfo :by="lastEdit.by?.profile?.name" :madeAt="lastEdit.madeAt" />
|
||||
</BubbleContainer>
|
||||
</template>
|
||||
<BubbleContainer :fromMe="lastEdit.by?.isMe">
|
||||
<BubbleBody>{{ msg.text }}</BubbleBody>
|
||||
<BubbleInfo :by="lastEdit.by?.profile?.name" :madeAt="lastEdit.madeAt" />
|
||||
</BubbleContainer>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { computed, defineComponent } from "vue";
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { CoList, CoMap, co } from "jazz-tools";
|
||||
import { CoList, CoMap, CoPlainText, co } from "jazz-tools";
|
||||
|
||||
export class Message extends CoMap {
|
||||
text = co.string;
|
||||
text = co.ref(CoPlainText);
|
||||
}
|
||||
|
||||
export class Chat extends CoList.Of(co.ref(Message)) {}
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import type { ID } from "jazz-tools";
|
||||
import { CoPlainText, type ID } from "jazz-tools";
|
||||
import { useCoState } from "jazz-vue";
|
||||
import { type PropType, computed, defineComponent, ref } from "vue";
|
||||
import ChatBody from "../components/ChatBody.vue";
|
||||
@@ -61,7 +61,12 @@ export default defineComponent({
|
||||
}
|
||||
|
||||
function handleSubmit(text: string) {
|
||||
chat?.value?.push(Message.create({ text }, { owner: chat.value._owner }));
|
||||
chat?.value?.push(
|
||||
Message.create(
|
||||
{ text: CoPlainText.create(text, chat.value._owner) },
|
||||
chat.value._owner,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return {
|
||||
|
||||
@@ -1,5 +1,47 @@
|
||||
# jazz-example-chat
|
||||
|
||||
## 0.0.196
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [8e5ff13]
|
||||
- jazz-inspector@0.13.29
|
||||
- jazz-react@0.13.29
|
||||
- jazz-tools@0.13.29
|
||||
|
||||
## 0.0.195
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-inspector@0.13.28
|
||||
- jazz-react@0.13.28
|
||||
- jazz-tools@0.13.28
|
||||
|
||||
## 0.0.194
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-inspector@0.13.27
|
||||
- jazz-react@0.13.27
|
||||
- jazz-tools@0.13.27
|
||||
|
||||
## 0.0.193
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [ff846d9]
|
||||
- jazz-tools@0.13.26
|
||||
- jazz-inspector@0.13.26
|
||||
- jazz-react@0.13.26
|
||||
|
||||
## 0.0.192
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-inspector@0.13.25
|
||||
- jazz-react@0.13.25
|
||||
- jazz-tools@0.13.25
|
||||
|
||||
## 0.0.191
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "jazz-example-chat",
|
||||
"private": true,
|
||||
"version": "0.0.191",
|
||||
"version": "0.0.196",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { createImage, useAccount, useCoState } from "jazz-react";
|
||||
import { Account, ID } from "jazz-tools";
|
||||
import { Account, CoPlainText, ID } from "jazz-tools";
|
||||
import { useState } from "react";
|
||||
import { Chat, Message } from "./schema.ts";
|
||||
import {
|
||||
@@ -36,7 +36,15 @@ export function ChatScreen(props: { chatID: ID<Chat> }) {
|
||||
}
|
||||
|
||||
createImage(file, { owner: chat._owner }).then((image) => {
|
||||
chat.push(Message.create({ text: file.name, image: image }, chat._owner));
|
||||
chat.push(
|
||||
Message.create(
|
||||
{
|
||||
text: CoPlainText.create(file.name, chat._owner),
|
||||
image: image,
|
||||
},
|
||||
chat._owner,
|
||||
),
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -66,7 +74,12 @@ export function ChatScreen(props: { chatID: ID<Chat> }) {
|
||||
|
||||
<TextInput
|
||||
onSubmit={(text) => {
|
||||
chat.push(Message.create({ text }, { owner: chat._owner }));
|
||||
chat.push(
|
||||
Message.create(
|
||||
{ text: CoPlainText.create(text, chat._owner) },
|
||||
chat._owner,
|
||||
),
|
||||
);
|
||||
}}
|
||||
/>
|
||||
</InputBar>
|
||||
@@ -75,7 +88,7 @@ export function ChatScreen(props: { chatID: ID<Chat> }) {
|
||||
}
|
||||
|
||||
function ChatBubble(props: { me: Account; msg: Message }) {
|
||||
if (!props.me.canRead(props.msg)) {
|
||||
if (!props.me.canRead(props.msg) || !props.msg.text?.toString()) {
|
||||
return (
|
||||
<BubbleContainer fromMe={false}>
|
||||
<BubbleBody fromMe={false}>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { CoList, CoMap, ImageDefinition, co } from "jazz-tools";
|
||||
import { CoList, CoMap, CoPlainText, ImageDefinition, co } from "jazz-tools";
|
||||
|
||||
export class Message extends CoMap {
|
||||
text = co.string;
|
||||
text = co.ref(CoPlainText);
|
||||
image = co.optional.ref(ImageDefinition);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import clsx from "clsx";
|
||||
import { ProgressiveImg } from "jazz-react";
|
||||
import { ImageDefinition } from "jazz-tools";
|
||||
import { CoPlainText, ImageDefinition } from "jazz-tools";
|
||||
import { ImageIcon } from "lucide-react";
|
||||
import { useId, useRef } from "react";
|
||||
|
||||
@@ -70,7 +70,10 @@ export function BubbleBody(props: {
|
||||
);
|
||||
}
|
||||
|
||||
export function BubbleText(props: { text: string; className?: string }) {
|
||||
export function BubbleText(props: {
|
||||
text: CoPlainText | string;
|
||||
className?: string;
|
||||
}) {
|
||||
return (
|
||||
<p className={clsx("px-2 leading-relaxed", props.className)}>
|
||||
{props.text}
|
||||
|
||||
@@ -1,5 +1,46 @@
|
||||
# minimal-auth-clerk
|
||||
|
||||
## 0.0.95
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-react@0.13.29
|
||||
- jazz-react-auth-clerk@0.13.29
|
||||
- jazz-tools@0.13.29
|
||||
|
||||
## 0.0.94
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-react@0.13.28
|
||||
- jazz-react-auth-clerk@0.13.28
|
||||
- jazz-tools@0.13.28
|
||||
|
||||
## 0.0.93
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-react@0.13.27
|
||||
- jazz-react-auth-clerk@0.13.27
|
||||
- jazz-tools@0.13.27
|
||||
|
||||
## 0.0.92
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [ff846d9]
|
||||
- jazz-tools@0.13.26
|
||||
- jazz-react@0.13.26
|
||||
- jazz-react-auth-clerk@0.13.26
|
||||
|
||||
## 0.0.91
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-react@0.13.25
|
||||
- jazz-react-auth-clerk@0.13.25
|
||||
- jazz-tools@0.13.25
|
||||
|
||||
## 0.0.90
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "clerk",
|
||||
"private": true,
|
||||
"version": "0.0.90",
|
||||
"version": "0.0.95",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
|
||||
@@ -1,5 +1,46 @@
|
||||
# file-share-svelte
|
||||
|
||||
## 0.0.79
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-svelte@0.13.29
|
||||
- jazz-tools@0.13.29
|
||||
- jazz-inspector-element@0.13.29
|
||||
|
||||
## 0.0.78
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-svelte@0.13.28
|
||||
- jazz-tools@0.13.28
|
||||
- jazz-inspector-element@0.13.28
|
||||
|
||||
## 0.0.77
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-svelte@0.13.27
|
||||
- jazz-tools@0.13.27
|
||||
- jazz-inspector-element@0.13.27
|
||||
|
||||
## 0.0.76
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [ff846d9]
|
||||
- jazz-tools@0.13.26
|
||||
- jazz-inspector-element@0.13.26
|
||||
- jazz-svelte@0.13.26
|
||||
|
||||
## 0.0.75
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-svelte@0.13.25
|
||||
- jazz-tools@0.13.25
|
||||
- jazz-inspector-element@0.13.25
|
||||
|
||||
## 0.0.74
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "file-share-svelte",
|
||||
"version": "0.0.74",
|
||||
"version": "0.0.79",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
|
||||
@@ -1,5 +1,47 @@
|
||||
# jazz-tailwind-demo-auth-starter
|
||||
|
||||
## 0.0.35
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [8e5ff13]
|
||||
- jazz-inspector@0.13.29
|
||||
- jazz-react@0.13.29
|
||||
- jazz-tools@0.13.29
|
||||
|
||||
## 0.0.34
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-inspector@0.13.28
|
||||
- jazz-react@0.13.28
|
||||
- jazz-tools@0.13.28
|
||||
|
||||
## 0.0.33
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-inspector@0.13.27
|
||||
- jazz-react@0.13.27
|
||||
- jazz-tools@0.13.27
|
||||
|
||||
## 0.0.32
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [ff846d9]
|
||||
- jazz-tools@0.13.26
|
||||
- jazz-inspector@0.13.26
|
||||
- jazz-react@0.13.26
|
||||
|
||||
## 0.0.31
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-inspector@0.13.25
|
||||
- jazz-react@0.13.25
|
||||
- jazz-tools@0.13.25
|
||||
|
||||
## 0.0.30
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "filestream",
|
||||
"private": true,
|
||||
"version": "0.0.30",
|
||||
"version": "0.0.35",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
|
||||
@@ -1,5 +1,41 @@
|
||||
# form
|
||||
|
||||
## 0.1.36
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-react@0.13.29
|
||||
- jazz-tools@0.13.29
|
||||
|
||||
## 0.1.35
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-react@0.13.28
|
||||
- jazz-tools@0.13.28
|
||||
|
||||
## 0.1.34
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-react@0.13.27
|
||||
- jazz-tools@0.13.27
|
||||
|
||||
## 0.1.33
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [ff846d9]
|
||||
- jazz-tools@0.13.26
|
||||
- jazz-react@0.13.26
|
||||
|
||||
## 0.1.32
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-react@0.13.25
|
||||
- jazz-tools@0.13.25
|
||||
|
||||
## 0.1.31
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "form",
|
||||
"private": true,
|
||||
"version": "0.1.31",
|
||||
"version": "0.1.36",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
|
||||
@@ -62,7 +62,7 @@ function CreateOrderForm({
|
||||
onSave: (draft: DraftBubbleTeaOrder) => void;
|
||||
}) {
|
||||
const draft = useCoState(DraftBubbleTeaOrder, id, {
|
||||
resolve: { addOns: true },
|
||||
resolve: { addOns: true, instructions: true },
|
||||
});
|
||||
|
||||
if (!draft) return;
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { CoPlainText } from "jazz-tools";
|
||||
import {
|
||||
BubbleTeaAddOnTypes,
|
||||
BubbleTeaBaseTeaTypes,
|
||||
@@ -12,6 +13,18 @@ export function OrderForm({
|
||||
order: BubbleTeaOrder | DraftBubbleTeaOrder;
|
||||
onSave?: (e: React.FormEvent<HTMLFormElement>) => void;
|
||||
}) {
|
||||
// Handles updates to the instructions field of the order.
|
||||
// If instructions already exist, applyDiff updates them incrementally.
|
||||
// Otherwise, creates a new CoPlainText instance for the instructions.
|
||||
const handleInstructionsChange = (
|
||||
e: React.ChangeEvent<HTMLTextAreaElement>,
|
||||
) => {
|
||||
if (order.instructions) {
|
||||
return order.instructions.applyDiff(e.target.value);
|
||||
}
|
||||
order.instructions = CoPlainText.create(e.target.value, order._owner);
|
||||
};
|
||||
|
||||
return (
|
||||
<form onSubmit={onSave} className="grid gap-5">
|
||||
<div className="flex flex-col gap-2">
|
||||
@@ -88,9 +101,9 @@ export function OrderForm({
|
||||
<textarea
|
||||
name="instructions"
|
||||
id="instructions"
|
||||
value={order.instructions}
|
||||
value={`${order.instructions}`}
|
||||
className="dark:bg-transparent"
|
||||
onChange={(e) => (order.instructions = e.target.value)}
|
||||
onChange={handleInstructionsChange}
|
||||
></textarea>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Account, CoList, CoMap, co } from "jazz-tools";
|
||||
import { Account, CoList, CoMap, CoPlainText, co } from "jazz-tools";
|
||||
|
||||
export const BubbleTeaAddOnTypes = [
|
||||
"Pearl",
|
||||
@@ -28,7 +28,7 @@ export class BubbleTeaOrder extends CoMap {
|
||||
addOns = co.ref(ListOfBubbleTeaAddOns);
|
||||
deliveryDate = co.Date;
|
||||
withMilk = co.boolean;
|
||||
instructions = co.optional.string;
|
||||
instructions = co.optional.ref(CoPlainText);
|
||||
}
|
||||
|
||||
export class DraftBubbleTeaOrder extends CoMap {
|
||||
@@ -36,7 +36,7 @@ export class DraftBubbleTeaOrder extends CoMap {
|
||||
addOns = co.optional.ref(ListOfBubbleTeaAddOns);
|
||||
deliveryDate = co.optional.Date;
|
||||
withMilk = co.optional.boolean;
|
||||
instructions = co.optional.string;
|
||||
instructions = co.optional.ref(CoPlainText);
|
||||
|
||||
get hasChanges() {
|
||||
return Object.keys(this._edits).length > 1 || this.addOns?.hasChanges;
|
||||
|
||||
@@ -1,5 +1,41 @@
|
||||
# image-upload
|
||||
|
||||
## 0.0.92
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-react@0.13.29
|
||||
- jazz-tools@0.13.29
|
||||
|
||||
## 0.0.91
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-react@0.13.28
|
||||
- jazz-tools@0.13.28
|
||||
|
||||
## 0.0.90
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-react@0.13.27
|
||||
- jazz-tools@0.13.27
|
||||
|
||||
## 0.0.89
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [ff846d9]
|
||||
- jazz-tools@0.13.26
|
||||
- jazz-react@0.13.26
|
||||
|
||||
## 0.0.88
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-react@0.13.25
|
||||
- jazz-tools@0.13.25
|
||||
|
||||
## 0.0.87
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "image-upload",
|
||||
"private": true,
|
||||
"version": "0.0.87",
|
||||
"version": "0.0.92",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
|
||||
@@ -1,5 +1,51 @@
|
||||
# jazz-example-inspector
|
||||
|
||||
## 0.0.146
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [eef1a5d]
|
||||
- Updated dependencies [8e5ff13]
|
||||
- Updated dependencies [191ae38]
|
||||
- Updated dependencies [daee7b9]
|
||||
- cojson@0.13.29
|
||||
- jazz-inspector@0.13.29
|
||||
- cojson-transport-ws@0.13.29
|
||||
|
||||
## 0.0.145
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [e7ccb2c]
|
||||
- Updated dependencies [422dbc4]
|
||||
- cojson@0.13.28
|
||||
- cojson-transport-ws@0.13.28
|
||||
- jazz-inspector@0.13.28
|
||||
|
||||
## 0.0.144
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [6357052]
|
||||
- cojson@0.13.27
|
||||
- cojson-transport-ws@0.13.27
|
||||
- jazz-inspector@0.13.27
|
||||
|
||||
## 0.0.143
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-inspector@0.13.26
|
||||
|
||||
## 0.0.142
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [a846e07]
|
||||
- cojson@0.13.25
|
||||
- cojson-transport-ws@0.13.25
|
||||
- jazz-inspector@0.13.25
|
||||
|
||||
## 0.0.141
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "jazz-inspector-app",
|
||||
"private": true,
|
||||
"version": "0.0.141",
|
||||
"version": "0.0.146",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
|
||||
@@ -1,5 +1,41 @@
|
||||
# multi-cursors
|
||||
|
||||
## 0.0.88
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-react@0.13.29
|
||||
- jazz-tools@0.13.29
|
||||
|
||||
## 0.0.87
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-react@0.13.28
|
||||
- jazz-tools@0.13.28
|
||||
|
||||
## 0.0.86
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-react@0.13.27
|
||||
- jazz-tools@0.13.27
|
||||
|
||||
## 0.0.85
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [ff846d9]
|
||||
- jazz-tools@0.13.26
|
||||
- jazz-react@0.13.26
|
||||
|
||||
## 0.0.84
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-react@0.13.25
|
||||
- jazz-tools@0.13.25
|
||||
|
||||
## 0.0.83
|
||||
|
||||
### Patch Changes
|
||||
|
||||