-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
update iframestamper and add an example for email auth #169
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@turnkey/iframe-stamper": minor | ||
--- | ||
|
||
- Add support for auth (e.g. via email), and include recovery under it. Note that this is a **breaking change**, as we are now using `injectCredentialBundle` as opposed to `injectRecoveryBundle` | ||
- Update protos |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
API_PUBLIC_KEY="<Turnkey API Public Key (that starts with 02 or 03)>" | ||
API_PRIVATE_KEY="<Turnkey API Private Key>" | ||
NEXT_PUBLIC_ORGANIZATION_ID="<Turnkey organization ID>" | ||
NEXT_PUBLIC_BASE_URL="https://api.turnkey.com" | ||
# Can be changed to a localhost iframe if you're modifying the auth flow | ||
# For production, the URL should not be changed and point to the primary Turnkey domain. | ||
NEXT_PUBLIC_AUTH_IFRAME_URL="https://auth.turnkey.com" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"extends": "next/core-web-vitals" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||
|
||
# dependencies | ||
/node_modules | ||
/.pnp | ||
.pnp.js | ||
|
||
# testing | ||
/coverage | ||
|
||
# next.js | ||
/.next/ | ||
/out/ | ||
|
||
# production | ||
/build | ||
|
||
# misc | ||
.DS_Store | ||
*.pem | ||
|
||
# debug | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
# local env files | ||
.env*.local | ||
|
||
# vercel | ||
.vercel | ||
|
||
# typescript | ||
*.tsbuildinfo | ||
next-env.d.ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Example: `email-auth` | ||
|
||
This example shows a complete email auth flow. It contains a NextJS app with: | ||
|
||
- a frontend application | ||
- a backend application | ||
|
||
The overall flow for email auth is outlined below: | ||
![Email auth flow diagram](./email_auth_steps.png) | ||
|
||
This example contains an example auth page as well as a stub API endpoint for "your business" (where the email is resolved into an organization ID). The creation of the hidden iframe is abstracted by our `@turnkey/iframe-stamper` package. For more information on email auth, [check out our documentation](https://docs.turnkey.com/getting-started/email-auth). | ||
|
||
## Getting started | ||
|
||
### 1/ Cloning the example | ||
|
||
Make sure you have `node` installed locally; we recommend using Node v16+. | ||
|
||
```bash | ||
$ git clone https://github.com/tkhq/sdk | ||
$ cd sdk/ | ||
$ corepack enable # Install `pnpm` | ||
$ pnpm install -r # Install dependencies | ||
$ pnpm run build-all # Compile source code | ||
$ cd examples/email-auth/ | ||
``` | ||
|
||
### 2/ Setting up Turnkey | ||
|
||
The first step is to set up your Turnkey organization and account. By following the [Quickstart](https://docs.turnkey.com/getting-started/quickstart) guide, you should have: | ||
|
||
- A public/private API key pair for Turnkey | ||
- An organization ID | ||
|
||
Once you've gathered these values, add them to a new `.env.local` file. Notice that your API private key should be securely managed and **_never_** be committed to git. | ||
|
||
```bash | ||
$ cp .env.local.example .env.local | ||
``` | ||
|
||
Now open `.env.local` and add the missing environment variables: | ||
|
||
- `API_PUBLIC_KEY` | ||
- `API_PRIVATE_KEY` | ||
- `NEXT_PUBLIC_ORGANIZATION_ID` | ||
- `NEXT_PUBLIC_BASE_URL` (the `NEXT_PUBLIC` prefix makes the env variable accessible to the frontend app) | ||
- `NEXT_PUBLIC_AUTH_IFRAME_URL` | ||
|
||
### 3/ Running the app | ||
|
||
```bash | ||
$ pnpm run dev | ||
``` | ||
|
||
This command will run a NextJS app on port 3000. If you navigate to http://localhost:3000 in your browser, you can follow the prompts to start an email auth. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/** @type {import('next').NextConfig} */ | ||
const nextConfig = {}; | ||
|
||
module.exports = nextConfig; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"name": "@turnkey/example-email-auth", | ||
"version": "0.1.0", | ||
"private": true, | ||
"scripts": { | ||
"dev": "next dev", | ||
"build": "next build", | ||
"start": "next start", | ||
"lint": "next lint", | ||
"typecheck": "tsc --noEmit" | ||
}, | ||
"dependencies": { | ||
"@turnkey/http": "workspace:*", | ||
"@turnkey/api-key-stamper": "workspace:*", | ||
"@turnkey/iframe-stamper": "workspace:*", | ||
"@types/node": "20.3.1", | ||
"@types/react": "18.2.14", | ||
"@types/react-dom": "18.2.6", | ||
"axios": "^1.4.0", | ||
"encoding": "^0.1.13", | ||
"eslint": "8.43.0", | ||
"eslint-config-next": "13.4.7", | ||
"esm": "^3.2.25", | ||
"install": "^0.13.0", | ||
"next": "13.4.7", | ||
"npm": "^9.7.2", | ||
"react": "18.2.0", | ||
"react-dom": "18.2.0", | ||
"react-hook-form": "^7.45.1", | ||
"typescript": "5.1.3" | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
"use client"; | ||
|
||
import { IframeStamper } from "@turnkey/iframe-stamper"; | ||
import { Dispatch, SetStateAction, useEffect, useState } from "react"; | ||
|
||
interface AuthProps { | ||
iframeUrl: string; | ||
turnkeyBaseUrl: string; | ||
setIframeStamper: Dispatch<SetStateAction<IframeStamper | null>>; | ||
} | ||
|
||
const TurnkeyIframeContainerId = "turnkey-iframe-container-id"; | ||
const TurnkeyIframeElementId = "turnkey-iframe-element-id"; | ||
|
||
export function Auth(props: AuthProps) { | ||
const [iframeStamper, setIframeStamper] = useState<IframeStamper | null>( | ||
null | ||
); | ||
|
||
useEffect(() => { | ||
if (!iframeStamper) { | ||
const iframeStamper = new IframeStamper({ | ||
iframeUrl: props.iframeUrl, | ||
iframeContainerId: TurnkeyIframeContainerId, | ||
iframeElementId: TurnkeyIframeElementId, | ||
}); | ||
iframeStamper.init().then(() => { | ||
setIframeStamper(iframeStamper); | ||
props.setIframeStamper(iframeStamper); | ||
}); | ||
} | ||
|
||
return () => { | ||
if (iframeStamper) { | ||
iframeStamper.clear(); | ||
setIframeStamper(null); | ||
} | ||
}; | ||
}, [props, iframeStamper, setIframeStamper]); | ||
|
||
return <div style={{ display: "none" }} id={TurnkeyIframeContainerId}></div>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import Document, { Html, Head, Main, NextScript } from "next/document"; | ||
|
||
class Example extends Document { | ||
render() { | ||
return ( | ||
<Html> | ||
<Head> | ||
<link rel="icon" type="image/svg+xml" href="/favicon.svg" /> | ||
</Head> | ||
<body> | ||
<Main /> | ||
<NextScript /> | ||
</body> | ||
</Html> | ||
); | ||
} | ||
} | ||
|
||
export default Example; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we flag this as major to follow semver? Another option is to keep compatibility and mark
injectRecoverBundle
as deprecated. Under the hood it can still send the same event (and if we do this, then we have a minor, backwards-compatible release)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no strong feelings on this one. maybe leave as minor/deprecation for now, and then have a stricter change later?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good to me! Let's keep both function names/implementation around then 👍
(and we can deprecate if we make a breaking change at some point)