@redzone/taunt-logins-ui-react 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.history/index_20251002141038.html +13 -0
- package/.history/index_20251002141344.html +13 -0
- package/.history/package_20251002154235.json +32 -0
- package/.history/package_20251002160110.json +33 -0
- package/.history/package_20251002161109.json +33 -0
- package/.history/package_20251002161124.json +32 -0
- package/.history/src/App_20251002141038.tsx +35 -0
- package/.history/src/App_20251002142848.tsx +15 -0
- package/.history/src/App_20251002152540.tsx +15 -0
- package/.history/src/App_20251002152831.tsx +17 -0
- package/.history/src/App_20251002153145.tsx +18 -0
- package/.history/src/App_20251002153323.tsx +25 -0
- package/.history/src/App_20251002153420.tsx +32 -0
- package/.history/src/App_20251002153429.tsx +33 -0
- package/.history/src/App_20251002153457.tsx +39 -0
- package/.history/src/App_20251002153516.tsx +39 -0
- package/.history/src/App_20251002153520.tsx +39 -0
- package/.history/src/App_20251002153546.tsx +41 -0
- package/.history/src/App_20251002154625.tsx +41 -0
- package/.history/src/App_20251002154740.tsx +47 -0
- package/.history/src/App_20251002154812.tsx +47 -0
- package/.history/src/App_20251002154841.tsx +47 -0
- package/.history/src/App_20251002154915.tsx +54 -0
- package/.history/src/App_20251002160347.tsx +54 -0
- package/.history/src/lib/exports_20251002160004.ts +0 -0
- package/.history/src/lib/exports_20251002160045.ts +3 -0
- package/.history/src/lib/magic_20251002142829.tsx +0 -0
- package/.history/src/lib/magic_20251002142848.tsx +44 -0
- package/.history/src/lib/magic_20251002152540.tsx +28 -0
- package/.history/src/lib/magic_20251002152543.tsx +28 -0
- package/.history/src/lib/magic_20251002152546.tsx +28 -0
- package/.history/src/lib/magic_20251002152802.tsx +47 -0
- package/.history/src/lib/magic_20251002154740.tsx +47 -0
- package/.history/src/lib/magic_20251002155035.tsx +47 -0
- package/.history/src/lib/magic_20251002160411.tsx +49 -0
- package/.history/src/lib/magic_20251002160428.tsx +49 -0
- package/.history/src/lib/magic_20251002161028.tsx +50 -0
- package/.history/src/lib/metamask_20251002141612.tsx +0 -0
- package/.history/src/lib/metamask_20251002142622.tsx +38 -0
- package/.history/src/lib/metamask_20251002142654.tsx +41 -0
- package/.history/src/lib/metamask_20251002142726.tsx +44 -0
- package/.history/src/lib/metamask_20251002142848.tsx +0 -0
- package/.history/src/lib/metamask_20251002152802.tsx +28 -0
- package/.history/src/lib/metamask_20251002153516.tsx +27 -0
- package/.history/src/lib/metamask_20251002154228.tsx +27 -0
- package/.history/src/lib/metamask_20251002154523.tsx +27 -0
- package/.history/src/lib/styling_20251002154448.css +0 -0
- package/.history/src/lib/styling_20251002154523.css +19 -0
- package/.history/src/lib/styling_20251002154531.css +19 -0
- package/.history/src/lib/styling_20251002154544.css +20 -0
- package/.history/src/lib/styling_20251002154548.css +19 -0
- package/.history/src/lib/styling_20251002160446.css +20 -0
- package/.history/src/lib/styling_20251002160511.css +23 -0
- package/.history/src/lib/styling_20251002160515.css +24 -0
- package/.history/src/lib/styling_20251002160815.css +24 -0
- package/.history/src/lib/styling_20251002160910.css +24 -0
- package/.history/src/lib/styling_20251002160915.css +24 -0
- package/.history/src/lib/styling_20251002160952.css +24 -0
- package/.history/src/lib/styling_20251002161001.css +24 -0
- package/.history/src/lib/styling_20251002161011.css +24 -0
- package/.history/src/lib/styling_20251002161016.css +24 -0
- package/.history/src/lib/styling_20251002161036.css +25 -0
- package/.history/src/lib/tauntContext_20251002142359.ts +0 -0
- package/.history/src/lib/tauntContext_20251002142622.ts +17 -0
- package/.history/src/lib/tauntContext_20251002152540.ts +22 -0
- package/.history/src/lib/tauntContext_20251002152802.ts +22 -0
- package/.history/src/lib/tauntProvider_20251002142503.tsx +0 -0
- package/.history/src/lib/tauntProvider_20251002142622.tsx +15 -0
- package/.history/src/lib/tauntProvider_20251002143158.tsx +19 -0
- package/.history/src/lib/tauntProvider_20251002144018.tsx +19 -0
- package/.history/src/lib/tauntProvider_20251002152234.tsx +40 -0
- package/.history/src/lib/tauntProvider_20251002152802.tsx +40 -0
- package/.history/src/lib/tauntProvider_20251002153101.tsx +49 -0
- package/.history/src/lib/taunt_20251002160026.ts +0 -0
- package/.history/src/lib/taunt_20251002160045.ts +2 -0
- package/.history/src/main_20251002141038.tsx +10 -0
- package/.history/src/main_20251002141444.tsx +12 -0
- package/.history/src/main_20251002160347.tsx +12 -0
- package/.history/vite.config_20251002141038.ts +7 -0
- package/.history/vite.config_20251002141323.ts +10 -0
- package/.prettierrc.mjs +22 -0
- package/README.md +73 -0
- package/eslint.config.js +23 -0
- package/index.html +13 -0
- package/package.json +32 -0
- package/public/vite.svg +1 -0
- package/src/App.css +42 -0
- package/src/App.tsx +54 -0
- package/src/index.css +68 -0
- package/src/lib/exports.ts +3 -0
- package/src/lib/magic.tsx +50 -0
- package/src/lib/metamask.tsx +27 -0
- package/src/lib/styling.css +25 -0
- package/src/lib/taunt.ts +2 -0
- package/src/lib/tauntContext.ts +22 -0
- package/src/lib/tauntProvider.tsx +49 -0
- package/src/main.tsx +12 -0
- package/tsconfig.app.json +28 -0
- package/tsconfig.json +7 -0
- package/tsconfig.node.json +26 -0
- package/vite.config.ts +10 -0
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { tauntMagicDidLogin, tauntMetamaskLogin } from "@redzone/taunt-logins"
|
|
2
|
+
import { useCallback, useState } from "react"
|
|
3
|
+
|
|
4
|
+
import { TauntContext } from "./tauntContext"
|
|
5
|
+
|
|
6
|
+
export const TauntProvider = ({
|
|
7
|
+
children,
|
|
8
|
+
tauntServiceEndpoint
|
|
9
|
+
}: {
|
|
10
|
+
children: React.ReactNode
|
|
11
|
+
tauntServiceEndpoint?: string
|
|
12
|
+
}) => {
|
|
13
|
+
const [deets, setDeets] = useState<{
|
|
14
|
+
accessToken: string
|
|
15
|
+
refreshToken: string
|
|
16
|
+
}>()
|
|
17
|
+
|
|
18
|
+
const otpMagicLogin = useCallback(
|
|
19
|
+
(email: string) => {
|
|
20
|
+
tauntMagicDidLogin(tauntServiceEndpoint!, email!).then(setDeets)
|
|
21
|
+
},
|
|
22
|
+
[tauntServiceEndpoint]
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
const metamaskLogin = useCallback(
|
|
26
|
+
() => tauntMetamaskLogin(tauntServiceEndpoint!).then(setDeets),
|
|
27
|
+
[tauntServiceEndpoint]
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
if (!tauntServiceEndpoint) {
|
|
31
|
+
return <div>tauntServiceEndpoint is required</div>
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return (
|
|
35
|
+
<TauntContext.Provider
|
|
36
|
+
value={{ tauntServiceEndpoint, deets, otpMagicLogin, metamaskLogin }}>
|
|
37
|
+
{children}
|
|
38
|
+
</TauntContext.Provider>
|
|
39
|
+
)
|
|
40
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import {
|
|
2
|
+
tauntMagicEmailOTPLogin,
|
|
3
|
+
tauntMetamaskLogin
|
|
4
|
+
} from "@redzone/taunt-logins"
|
|
5
|
+
import { useCallback, useState } from "react"
|
|
6
|
+
|
|
7
|
+
import { TauntContext } from "./tauntContext"
|
|
8
|
+
|
|
9
|
+
export const TauntProvider = ({
|
|
10
|
+
children,
|
|
11
|
+
tauntServiceEndpoint,
|
|
12
|
+
magicKey
|
|
13
|
+
}: {
|
|
14
|
+
children: React.ReactNode
|
|
15
|
+
tauntServiceEndpoint?: string
|
|
16
|
+
magicKey?: string
|
|
17
|
+
}) => {
|
|
18
|
+
const [deets, setDeets] = useState<{
|
|
19
|
+
accessToken: string
|
|
20
|
+
refreshToken: string
|
|
21
|
+
}>()
|
|
22
|
+
|
|
23
|
+
const otpMagicLogin = useCallback(
|
|
24
|
+
(email: string) => {
|
|
25
|
+
if (!magicKey) throw new Error("magicKey is required for OTP login")
|
|
26
|
+
|
|
27
|
+
tauntMagicEmailOTPLogin(tauntServiceEndpoint!, magicKey, email!).then(
|
|
28
|
+
setDeets
|
|
29
|
+
)
|
|
30
|
+
},
|
|
31
|
+
[tauntServiceEndpoint]
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
const metamaskLogin = useCallback(
|
|
35
|
+
() => tauntMetamaskLogin(tauntServiceEndpoint!).then(setDeets),
|
|
36
|
+
[tauntServiceEndpoint]
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
if (!tauntServiceEndpoint) {
|
|
40
|
+
return <div>tauntServiceEndpoint is required</div>
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return (
|
|
44
|
+
<TauntContext.Provider
|
|
45
|
+
value={{ tauntServiceEndpoint, deets, otpMagicLogin, metamaskLogin }}>
|
|
46
|
+
{children}
|
|
47
|
+
</TauntContext.Provider>
|
|
48
|
+
)
|
|
49
|
+
}
|
|
File without changes
|
package/.prettierrc.mjs
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @type {import('prettier').Options}
|
|
3
|
+
*/
|
|
4
|
+
export default {
|
|
5
|
+
printWidth: 80,
|
|
6
|
+
tabWidth: 2,
|
|
7
|
+
useTabs: false,
|
|
8
|
+
semi: false,
|
|
9
|
+
singleQuote: false,
|
|
10
|
+
trailingComma: "none",
|
|
11
|
+
bracketSpacing: true,
|
|
12
|
+
bracketSameLine: true,
|
|
13
|
+
plugins: ["@ianvs/prettier-plugin-sort-imports"],
|
|
14
|
+
importOrder: [
|
|
15
|
+
"<BUILTIN_MODULES>", // Node.js built-in modules
|
|
16
|
+
"<THIRD_PARTY_MODULES>", // Imports not matched by other special words or groups.
|
|
17
|
+
"",
|
|
18
|
+
"^~(.*)$",
|
|
19
|
+
"",
|
|
20
|
+
"^[./]"
|
|
21
|
+
]
|
|
22
|
+
}
|
package/README.md
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# React + TypeScript + Vite
|
|
2
|
+
|
|
3
|
+
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
|
|
4
|
+
|
|
5
|
+
Currently, two official plugins are available:
|
|
6
|
+
|
|
7
|
+
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react) uses [Babel](https://babeljs.io/) (or [oxc](https://oxc.rs) when used in [rolldown-vite](https://vite.dev/guide/rolldown)) for Fast Refresh
|
|
8
|
+
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
|
|
9
|
+
|
|
10
|
+
## React Compiler
|
|
11
|
+
|
|
12
|
+
The React Compiler is currently not compatible with SWC. See [this issue](https://github.com/vitejs/vite-plugin-react/issues/428) for tracking the progress.
|
|
13
|
+
|
|
14
|
+
## Expanding the ESLint configuration
|
|
15
|
+
|
|
16
|
+
If you are developing a production application, we recommend updating the configuration to enable type-aware lint rules:
|
|
17
|
+
|
|
18
|
+
```js
|
|
19
|
+
export default defineConfig([
|
|
20
|
+
globalIgnores(['dist']),
|
|
21
|
+
{
|
|
22
|
+
files: ['**/*.{ts,tsx}'],
|
|
23
|
+
extends: [
|
|
24
|
+
// Other configs...
|
|
25
|
+
|
|
26
|
+
// Remove tseslint.configs.recommended and replace with this
|
|
27
|
+
tseslint.configs.recommendedTypeChecked,
|
|
28
|
+
// Alternatively, use this for stricter rules
|
|
29
|
+
tseslint.configs.strictTypeChecked,
|
|
30
|
+
// Optionally, add this for stylistic rules
|
|
31
|
+
tseslint.configs.stylisticTypeChecked,
|
|
32
|
+
|
|
33
|
+
// Other configs...
|
|
34
|
+
],
|
|
35
|
+
languageOptions: {
|
|
36
|
+
parserOptions: {
|
|
37
|
+
project: ['./tsconfig.node.json', './tsconfig.app.json'],
|
|
38
|
+
tsconfigRootDir: import.meta.dirname,
|
|
39
|
+
},
|
|
40
|
+
// other options...
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
])
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
You can also install [eslint-plugin-react-x](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-x) and [eslint-plugin-react-dom](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-dom) for React-specific lint rules:
|
|
47
|
+
|
|
48
|
+
```js
|
|
49
|
+
// eslint.config.js
|
|
50
|
+
import reactX from 'eslint-plugin-react-x'
|
|
51
|
+
import reactDom from 'eslint-plugin-react-dom'
|
|
52
|
+
|
|
53
|
+
export default defineConfig([
|
|
54
|
+
globalIgnores(['dist']),
|
|
55
|
+
{
|
|
56
|
+
files: ['**/*.{ts,tsx}'],
|
|
57
|
+
extends: [
|
|
58
|
+
// Other configs...
|
|
59
|
+
// Enable lint rules for React
|
|
60
|
+
reactX.configs['recommended-typescript'],
|
|
61
|
+
// Enable lint rules for React DOM
|
|
62
|
+
reactDom.configs.recommended,
|
|
63
|
+
],
|
|
64
|
+
languageOptions: {
|
|
65
|
+
parserOptions: {
|
|
66
|
+
project: ['./tsconfig.node.json', './tsconfig.app.json'],
|
|
67
|
+
tsconfigRootDir: import.meta.dirname,
|
|
68
|
+
},
|
|
69
|
+
// other options...
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
])
|
|
73
|
+
```
|
package/eslint.config.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import js from '@eslint/js'
|
|
2
|
+
import globals from 'globals'
|
|
3
|
+
import reactHooks from 'eslint-plugin-react-hooks'
|
|
4
|
+
import reactRefresh from 'eslint-plugin-react-refresh'
|
|
5
|
+
import tseslint from 'typescript-eslint'
|
|
6
|
+
import { defineConfig, globalIgnores } from 'eslint/config'
|
|
7
|
+
|
|
8
|
+
export default defineConfig([
|
|
9
|
+
globalIgnores(['dist']),
|
|
10
|
+
{
|
|
11
|
+
files: ['**/*.{ts,tsx}'],
|
|
12
|
+
extends: [
|
|
13
|
+
js.configs.recommended,
|
|
14
|
+
tseslint.configs.recommended,
|
|
15
|
+
reactHooks.configs['recommended-latest'],
|
|
16
|
+
reactRefresh.configs.vite,
|
|
17
|
+
],
|
|
18
|
+
languageOptions: {
|
|
19
|
+
ecmaVersion: 2020,
|
|
20
|
+
globals: globals.browser,
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
])
|
package/index.html
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
|
+
<title>redzone-taunt-logins-ui-react</title>
|
|
8
|
+
</head>
|
|
9
|
+
<body>
|
|
10
|
+
<div id="root"></div>
|
|
11
|
+
<script type="module" src="/src/main.tsx"></script>
|
|
12
|
+
</body>
|
|
13
|
+
</html>
|
package/package.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@redzone/taunt-logins-ui-react",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "lib/exports.ts",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"dev": "vite",
|
|
8
|
+
"build": "tsc -b && vite build",
|
|
9
|
+
"lint": "eslint .",
|
|
10
|
+
"preview": "vite preview"
|
|
11
|
+
},
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"@redzone/taunt-logins": "^0.0.3",
|
|
14
|
+
"react": "^19.1.1",
|
|
15
|
+
"react-dom": "^19.1.1"
|
|
16
|
+
},
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"@eslint/js": "^9.36.0",
|
|
19
|
+
"@ianvs/prettier-plugin-sort-imports": "^4.7.0",
|
|
20
|
+
"@types/node": "^24.6.0",
|
|
21
|
+
"@types/react": "^19.1.16",
|
|
22
|
+
"@types/react-dom": "^19.1.9",
|
|
23
|
+
"@vitejs/plugin-react-swc": "^4.1.0",
|
|
24
|
+
"eslint": "^9.36.0",
|
|
25
|
+
"eslint-plugin-react-hooks": "^5.2.0",
|
|
26
|
+
"eslint-plugin-react-refresh": "^0.4.22",
|
|
27
|
+
"globals": "^16.4.0",
|
|
28
|
+
"typescript": "~5.9.3",
|
|
29
|
+
"typescript-eslint": "^8.45.0",
|
|
30
|
+
"vite": "^7.1.7"
|
|
31
|
+
}
|
|
32
|
+
}
|
package/public/vite.svg
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>
|
package/src/App.css
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
#root {
|
|
2
|
+
max-width: 1280px;
|
|
3
|
+
margin: 0 auto;
|
|
4
|
+
padding: 2rem;
|
|
5
|
+
text-align: center;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
.logo {
|
|
9
|
+
height: 6em;
|
|
10
|
+
padding: 1.5em;
|
|
11
|
+
will-change: filter;
|
|
12
|
+
transition: filter 300ms;
|
|
13
|
+
}
|
|
14
|
+
.logo:hover {
|
|
15
|
+
filter: drop-shadow(0 0 2em #646cffaa);
|
|
16
|
+
}
|
|
17
|
+
.logo.react:hover {
|
|
18
|
+
filter: drop-shadow(0 0 2em #61dafbaa);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
@keyframes logo-spin {
|
|
22
|
+
from {
|
|
23
|
+
transform: rotate(0deg);
|
|
24
|
+
}
|
|
25
|
+
to {
|
|
26
|
+
transform: rotate(360deg);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
@media (prefers-reduced-motion: no-preference) {
|
|
31
|
+
a:nth-of-type(2) .logo {
|
|
32
|
+
animation: logo-spin infinite 20s linear;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.card {
|
|
37
|
+
padding: 2em;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
.read-the-docs {
|
|
41
|
+
color: #888;
|
|
42
|
+
}
|
package/src/App.tsx
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// import "./App.css"
|
|
2
|
+
|
|
3
|
+
import { MagicEmailInput } from "./lib/magic"
|
|
4
|
+
import { MetaMaskButton } from "./lib/metamask"
|
|
5
|
+
import { useTaunt } from "./lib/tauntContext"
|
|
6
|
+
import { TauntProvider } from "./lib/tauntProvider"
|
|
7
|
+
|
|
8
|
+
function App() {
|
|
9
|
+
return (
|
|
10
|
+
<TauntProvider
|
|
11
|
+
tauntServiceEndpoint={import.meta.env.VITE_TAUNT_SERVICE_ENDPOINT}
|
|
12
|
+
magicKey={import.meta.env.VITE_MAGIC_KEY}>
|
|
13
|
+
<div
|
|
14
|
+
style={{
|
|
15
|
+
display: "flex",
|
|
16
|
+
flexDirection: "column",
|
|
17
|
+
gap: 8,
|
|
18
|
+
alignItems: "center"
|
|
19
|
+
}}>
|
|
20
|
+
<MagicEmailInput />
|
|
21
|
+
<MetaMaskButton />
|
|
22
|
+
<LogoutButton />
|
|
23
|
+
<TauntDeets />
|
|
24
|
+
</div>
|
|
25
|
+
</TauntProvider>
|
|
26
|
+
)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function LogoutButton() {
|
|
30
|
+
const { deets } = useTaunt()
|
|
31
|
+
if (!deets) return null
|
|
32
|
+
|
|
33
|
+
return (
|
|
34
|
+
<button
|
|
35
|
+
className="ml-2 p-2 bg-blue-500 text-white rounded-md"
|
|
36
|
+
type="button">
|
|
37
|
+
Logout
|
|
38
|
+
</button>
|
|
39
|
+
)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function TauntDeets() {
|
|
43
|
+
const { deets } = useTaunt()
|
|
44
|
+
return (
|
|
45
|
+
<textarea
|
|
46
|
+
rows={5}
|
|
47
|
+
cols={50}
|
|
48
|
+
value={JSON.stringify(deets, null, 2)}
|
|
49
|
+
readOnly
|
|
50
|
+
/>
|
|
51
|
+
)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export default App
|
package/src/index.css
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
:root {
|
|
2
|
+
font-family: system-ui, Avenir, Helvetica, Arial, sans-serif;
|
|
3
|
+
line-height: 1.5;
|
|
4
|
+
font-weight: 400;
|
|
5
|
+
|
|
6
|
+
color-scheme: light dark;
|
|
7
|
+
color: rgba(255, 255, 255, 0.87);
|
|
8
|
+
background-color: #242424;
|
|
9
|
+
|
|
10
|
+
font-synthesis: none;
|
|
11
|
+
text-rendering: optimizeLegibility;
|
|
12
|
+
-webkit-font-smoothing: antialiased;
|
|
13
|
+
-moz-osx-font-smoothing: grayscale;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
a {
|
|
17
|
+
font-weight: 500;
|
|
18
|
+
color: #646cff;
|
|
19
|
+
text-decoration: inherit;
|
|
20
|
+
}
|
|
21
|
+
a:hover {
|
|
22
|
+
color: #535bf2;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
body {
|
|
26
|
+
margin: 0;
|
|
27
|
+
display: flex;
|
|
28
|
+
place-items: center;
|
|
29
|
+
min-width: 320px;
|
|
30
|
+
min-height: 100vh;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
h1 {
|
|
34
|
+
font-size: 3.2em;
|
|
35
|
+
line-height: 1.1;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
button {
|
|
39
|
+
border-radius: 8px;
|
|
40
|
+
border: 1px solid transparent;
|
|
41
|
+
padding: 0.6em 1.2em;
|
|
42
|
+
font-size: 1em;
|
|
43
|
+
font-weight: 500;
|
|
44
|
+
font-family: inherit;
|
|
45
|
+
background-color: #1a1a1a;
|
|
46
|
+
cursor: pointer;
|
|
47
|
+
transition: border-color 0.25s;
|
|
48
|
+
}
|
|
49
|
+
button:hover {
|
|
50
|
+
border-color: #646cff;
|
|
51
|
+
}
|
|
52
|
+
button:focus,
|
|
53
|
+
button:focus-visible {
|
|
54
|
+
outline: 4px auto -webkit-focus-ring-color;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
@media (prefers-color-scheme: light) {
|
|
58
|
+
:root {
|
|
59
|
+
color: #213547;
|
|
60
|
+
background-color: #ffffff;
|
|
61
|
+
}
|
|
62
|
+
a:hover {
|
|
63
|
+
color: #747bff;
|
|
64
|
+
}
|
|
65
|
+
button {
|
|
66
|
+
background-color: #f9f9f9;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { useCallback, useMemo, useState } from "react"
|
|
2
|
+
|
|
3
|
+
import "./styling.css"
|
|
4
|
+
|
|
5
|
+
import { useTaunt } from "./tauntContext"
|
|
6
|
+
|
|
7
|
+
export const MagicEmailInput = ({
|
|
8
|
+
onEmail
|
|
9
|
+
}: {
|
|
10
|
+
onEmail?: (email: string) => void
|
|
11
|
+
}) => {
|
|
12
|
+
const { otpMagicLogin } = useTaunt()
|
|
13
|
+
const [email, setEmail] = useState<string>()
|
|
14
|
+
|
|
15
|
+
const initialised = useMemo(() => email !== undefined, [email])
|
|
16
|
+
|
|
17
|
+
const validEmail = useMemo(() => {
|
|
18
|
+
const validRegex =
|
|
19
|
+
/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/
|
|
20
|
+
return email?.match(validRegex) ? email : undefined
|
|
21
|
+
}, [email])
|
|
22
|
+
|
|
23
|
+
const runMagic = useCallback(() => {
|
|
24
|
+
if (!validEmail) return
|
|
25
|
+
|
|
26
|
+
if (onEmail) {
|
|
27
|
+
onEmail(email!)
|
|
28
|
+
} else {
|
|
29
|
+
otpMagicLogin(email!)
|
|
30
|
+
}
|
|
31
|
+
}, [validEmail, onEmail])
|
|
32
|
+
|
|
33
|
+
return (
|
|
34
|
+
<div style={{ display: "flex", flexDirection: "row", gap: 8 }}>
|
|
35
|
+
{initialised && !validEmail && (
|
|
36
|
+
<div style={{ color: "red" }}>Please enter a valid email</div>
|
|
37
|
+
)}
|
|
38
|
+
<input
|
|
39
|
+
className="rdz-input"
|
|
40
|
+
onChange={(e) => setEmail(e.target.value ? e.target.value : undefined)}
|
|
41
|
+
placeholder="Enter your email"
|
|
42
|
+
type="email"
|
|
43
|
+
value={email}
|
|
44
|
+
/>
|
|
45
|
+
<button className="rdz-button" onClick={runMagic} type="button">
|
|
46
|
+
Send Magic Link
|
|
47
|
+
</button>
|
|
48
|
+
</div>
|
|
49
|
+
)
|
|
50
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { useCallback } from "react"
|
|
2
|
+
|
|
3
|
+
import "./styling.css"
|
|
4
|
+
|
|
5
|
+
import { useTaunt } from "./tauntContext"
|
|
6
|
+
|
|
7
|
+
export const MetaMaskButton = ({
|
|
8
|
+
openMetamask
|
|
9
|
+
}: {
|
|
10
|
+
openMetamask?: () => void
|
|
11
|
+
}) => {
|
|
12
|
+
const { metamaskLogin } = useTaunt()
|
|
13
|
+
|
|
14
|
+
const runMetamask = useCallback(() => {
|
|
15
|
+
if (openMetamask) {
|
|
16
|
+
openMetamask()
|
|
17
|
+
} else {
|
|
18
|
+
metamaskLogin()
|
|
19
|
+
}
|
|
20
|
+
}, [metamaskLogin, openMetamask])
|
|
21
|
+
|
|
22
|
+
return (
|
|
23
|
+
<button className="rdz-button" onClick={runMetamask}>
|
|
24
|
+
Login with Metamask
|
|
25
|
+
</button>
|
|
26
|
+
)
|
|
27
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
.rdz-button,
|
|
2
|
+
.rdz-input {
|
|
3
|
+
font-family: Avenir, Helvetica, Arial, sans-serif !important;
|
|
4
|
+
line-height: 1.5;
|
|
5
|
+
font-weight: 400 !important;
|
|
6
|
+
|
|
7
|
+
color: lightgray;
|
|
8
|
+
border-radius: 8px;
|
|
9
|
+
border: 1px solid transparent;
|
|
10
|
+
padding: 0.6em 1.2em;
|
|
11
|
+
font-size: 1em;
|
|
12
|
+
font-weight: 500;
|
|
13
|
+
font-family: inherit;
|
|
14
|
+
background-color: #1a1a1a;
|
|
15
|
+
cursor: pointer;
|
|
16
|
+
transition: border-color 0.25s;
|
|
17
|
+
|
|
18
|
+
&:hover {
|
|
19
|
+
border-color: #646cff;
|
|
20
|
+
}
|
|
21
|
+
&:focus,
|
|
22
|
+
&:focus-visible {
|
|
23
|
+
outline: 4px auto -webkit-focus-ring-color;
|
|
24
|
+
}
|
|
25
|
+
}
|
package/src/lib/taunt.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { createContext, useContext } from "react"
|
|
2
|
+
|
|
3
|
+
type ContextProps = {
|
|
4
|
+
tauntServiceEndpoint: string
|
|
5
|
+
deets?: { accessToken: string; refreshToken: string }
|
|
6
|
+
metamaskLogin: () => void
|
|
7
|
+
otpMagicLogin: (email: string) => void
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const TauntContext = createContext<ContextProps>({
|
|
11
|
+
tauntServiceEndpoint: "",
|
|
12
|
+
metamaskLogin: () => {},
|
|
13
|
+
otpMagicLogin: () => {}
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
export function useTaunt() {
|
|
17
|
+
const ctx = useContext(TauntContext)
|
|
18
|
+
if (!ctx) {
|
|
19
|
+
throw new Error("useTaunt must be used within a TauntProvider")
|
|
20
|
+
}
|
|
21
|
+
return ctx
|
|
22
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import {
|
|
2
|
+
tauntMagicEmailOTPLogin,
|
|
3
|
+
tauntMetamaskLogin
|
|
4
|
+
} from "@redzone/taunt-logins"
|
|
5
|
+
import { useCallback, useState } from "react"
|
|
6
|
+
|
|
7
|
+
import { TauntContext } from "./tauntContext"
|
|
8
|
+
|
|
9
|
+
export const TauntProvider = ({
|
|
10
|
+
children,
|
|
11
|
+
tauntServiceEndpoint,
|
|
12
|
+
magicKey
|
|
13
|
+
}: {
|
|
14
|
+
children: React.ReactNode
|
|
15
|
+
tauntServiceEndpoint?: string
|
|
16
|
+
magicKey?: string
|
|
17
|
+
}) => {
|
|
18
|
+
const [deets, setDeets] = useState<{
|
|
19
|
+
accessToken: string
|
|
20
|
+
refreshToken: string
|
|
21
|
+
}>()
|
|
22
|
+
|
|
23
|
+
const otpMagicLogin = useCallback(
|
|
24
|
+
(email: string) => {
|
|
25
|
+
if (!magicKey) throw new Error("magicKey is required for OTP login")
|
|
26
|
+
|
|
27
|
+
tauntMagicEmailOTPLogin(tauntServiceEndpoint!, magicKey, email!).then(
|
|
28
|
+
setDeets
|
|
29
|
+
)
|
|
30
|
+
},
|
|
31
|
+
[tauntServiceEndpoint]
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
const metamaskLogin = useCallback(
|
|
35
|
+
() => tauntMetamaskLogin(tauntServiceEndpoint!).then(setDeets),
|
|
36
|
+
[tauntServiceEndpoint]
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
if (!tauntServiceEndpoint) {
|
|
40
|
+
return <div>tauntServiceEndpoint is required</div>
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return (
|
|
44
|
+
<TauntContext.Provider
|
|
45
|
+
value={{ tauntServiceEndpoint, deets, otpMagicLogin, metamaskLogin }}>
|
|
46
|
+
{children}
|
|
47
|
+
</TauntContext.Provider>
|
|
48
|
+
)
|
|
49
|
+
}
|