forked from redwoodjs/redwood
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of github.com:redwoodjs/redwood into feat/vite-ssr
* 'main' of github.com:redwoodjs/redwood: (162 commits) fix(deps): update dependency @escape.tech/graphql-armor to v1.8.0 (redwoodjs#7922) chore(deps): update dependency @playwright/test to v1.32.1 (redwoodjs#7924) chore(deps): update dependency @testing-library/dom to v9.2.0 (redwoodjs#7921) chore(deps): update dependency rimraf to v4 (redwoodjs#7907) fix(deps): update dependency react-hook-form to v7.43.8 (redwoodjs#7920) fix(deps): update dependency @fastify/http-proxy to v9 (redwoodjs#7889) fix(deps): update dependency @types/node to v16.18.20 (redwoodjs#7919) chore(deps): update dependency @replayio/playwright to v0.3.27 (redwoodjs#7918) fix(Clerk): call reauthenticate before navigating (redwoodjs#7917) chore(deps): update dependency esbuild to v0.17.13 (redwoodjs#7915) chore(deps): update dependency lerna to v6.6.1 (redwoodjs#7916) chore(deps): update dependency @tsd/typescript to v5 (redwoodjs#7856) chore(deps): update dependency @testing-library/dom to v9.1.0 (redwoodjs#7914) fix(deps): update dependency msw to v1.2.1 (redwoodjs#7911) chore(deps): update dependency @types/react to v18.0.29 (redwoodjs#7912) chore(deps): update dependency nx to v15.8.9 (redwoodjs#7913) Fix for directUrl usage during testing (redwoodjs#7898) fix(deps): update dependency prettier to v2.8.7 (redwoodjs#7908) chore(deps): update dependency @nrwl/nx-cloud to v15.3.2 (redwoodjs#7904) fix(deps): update dependency @types/node to v16.18.19 (redwoodjs#7906) ...
- Loading branch information
Showing
298 changed files
with
11,699 additions
and
8,784 deletions.
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
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
516 changes: 258 additions & 258 deletions
516
.yarn/releases/yarn-3.4.1.cjs → .yarn/releases/yarn-3.5.0.cjs
Large diffs are not rendered by default.
Oops, something went wrong.
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
516 changes: 258 additions & 258 deletions
516
...est-project/.yarn/releases/yarn-3.4.1.cjs → ...est-project/.yarn/releases/yarn-3.5.0.cjs
Large diffs are not rendered by default.
Oops, something went wrong.
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
File renamed without changes.
File renamed without changes.
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 |
---|---|---|
|
@@ -20,5 +20,5 @@ | |
"prisma": { | ||
"seed": "yarn rw exec seed" | ||
}, | ||
"packageManager": "yarn@3.3.1" | ||
"packageManager": "yarn@3.5.0" | ||
} |
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
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 |
---|---|---|
|
@@ -15,6 +15,8 @@ yarn rw setup auth supabase | |
This installs all the packages, writes all the files, and makes all the code modifications you need. | ||
For a detailed explanation of all the api- and web-side changes that aren't exclusive to Supabase, see the top-level [Authentication](../authentication.md) doc. For now, let's focus on Supabase's side of things. | ||
|
||
## Setup | ||
|
||
If you don't have a Supabase account yet, now's the time to make one: navigate to https://supabase.com and click "Start your project" in the top right. Then sign up and create an organization and a project. | ||
|
||
While Supabase creates your project, it thoughtfully shows your project's API keys. | ||
|
@@ -42,8 +44,23 @@ Lastly, in `redwood.toml`, include `SUPABASE_URL` and `SUPABASE_KEY` in the list | |
includeEnvironmentVariables = ["SUPABASE_URL", "SUPABASE_KEY"] | ||
``` | ||
|
||
That should be enough; now, things should just work. | ||
|
||
|
||
## Authentication UI | ||
|
||
Supabase doesn't redirect to a hosted sign-up page or open a sign-up modal. | ||
In a real app, you'd build a form here, but we're going to hardcode an email and password. | ||
|
||
### Basic Example | ||
|
||
After you sign up, head to your inbox: there should be a confirmation email from Supabase waiting for you. | ||
|
||
Click the link, then head back to your app. | ||
Once you refresh the page, you should see `{"isAuthenticated":true}` on the page. | ||
|
||
|
||
Let's make sure: if this is a brand new project, generate a home page. | ||
|
||
There we'll try to sign up by destructuring `signUp` from the `useAuth` hook (import that from `'src/auth'`). We'll also destructure and display `isAuthenticated` to see if it worked: | ||
|
||
```tsx title="web/src/pages/HomePage.tsx" | ||
|
@@ -66,8 +83,195 @@ const HomePage = () => { | |
} | ||
``` | ||
|
||
Supabase doesn't redirect to a hosted sign-up page or open a sign-up modal. | ||
In a real app, you'd build a form here, but we're going to hardcode an email and password. | ||
After you sign up, head to your inbox: there should be a confirmation email from Supabase waiting for you. | ||
Click the link, then head back to your app. | ||
Once you refresh the page, you should see `{"isAuthenticated":true}` on the page. | ||
## Authentication Reference | ||
|
||
You will notice that [Supabase Javascript SDK Auth API](https://supabase.com/docs/reference/javascript/auth-api) reference documentation presents methods to sign in with the various integrations Supabase supports: password, OAuth, IDToken, SSO, etc. | ||
|
||
The RedwoodJS implementation of Supabase authentication supports these as well, but within the `logIn` method of the `useAuth` hook. | ||
|
||
That means that you will see that Supabase documents sign in with email password as: | ||
|
||
```ts | ||
const { data, error } = await supabase.auth.signInWithPassword({ | ||
email: '[email protected]', | ||
password: 'example-password', | ||
}) | ||
``` | ||
|
||
In RedwoodJS, you will always use `logIn` and pass the necessary credential options and also an `authenticationMethod` to declare how you want to authenticate. | ||
|
||
```ts | ||
const { logIn } = useAuth() | ||
|
||
await logIn({ | ||
authenticationMethod: 'password', | ||
email: '[email protected]', | ||
password: 'example-password', | ||
}) | ||
``` | ||
|
||
### Sign Up with email and password | ||
|
||
Creates a new user. | ||
|
||
```ts | ||
const { signUp } = useAuth() | ||
|
||
await signUp({ | ||
email: '[email protected]', | ||
password: 'example-password', | ||
}) | ||
``` | ||
|
||
### Sign in a user with email and password | ||
|
||
Log in an existing user with an email and password or phone and password. | ||
|
||
* Requires either an email and password or a phone number and password. | ||
|
||
```ts | ||
const { logIn } = useAuth() | ||
|
||
await logIn({ | ||
authenticationMethod: 'password', | ||
email: '[email protected]', | ||
password: 'example-password', | ||
}) | ||
``` | ||
|
||
### Sign in a user through Passwordless/OTP | ||
|
||
Log in a user using magiclink or a one-time password (OTP). | ||
|
||
* Requires either an email or phone number. | ||
|
||
* This method is used for passwordless sign-ins where a OTP is sent to the user's email or phone number. | ||
|
||
```ts | ||
const { logIn } = useAuth() | ||
|
||
await logIn({ | ||
authenticationMethod: 'otp', | ||
email: '[email protected]', | ||
options: { | ||
emailRedirectTo: 'https://example.com/welcome' | ||
} | ||
}) | ||
``` | ||
|
||
### Sign in a user through OAuth | ||
|
||
Log in an existing user via a third-party provider. | ||
|
||
* This method is used for signing in using a third-party provider. | ||
|
||
* Supabase supports many different [third-party providers](https://supabase.com/docs/guides/auth#providers). | ||
|
||
```ts | ||
const { logIn } = useAuth() | ||
|
||
await logIn({ | ||
authenticationMethod: 'otp', | ||
email: '[email protected]', | ||
options: { | ||
emailRedirectTo: 'https://example.com/welcome' | ||
} | ||
}) | ||
``` | ||
|
||
### Sign in a user with IDToken | ||
|
||
Log in a user using IDToken. | ||
|
||
```ts | ||
const { logIn } = useAuth() | ||
|
||
await logIn({ | ||
authenticationMethod: 'id_token', | ||
provider: 'apple', | ||
token: 'cortland-apple-id-token', | ||
}) | ||
``` | ||
|
||
### Sign in a user with SSO | ||
|
||
Log in a user using IDToken. | ||
|
||
```ts | ||
const { logIn } = useAuth() | ||
|
||
await logIn({ | ||
authenticationMethod: 'sso', | ||
providerId: 'sso-provider-identity-uuid', | ||
domain: 'example.com', | ||
}) | ||
``` | ||
|
||
### Sign out a user | ||
|
||
Inside a browser context, signOut() will remove the logged in user from the browser session and log them out - removing all items from localStorage and then trigger a "SIGNED_OUT" event. | ||
|
||
In order to use the signOut() method, the user needs to be signed in first. | ||
|
||
```ts | ||
const { logOut } = useAuth() | ||
|
||
logOut() | ||
``` | ||
|
||
|
||
### Verify and log in through OTP | ||
|
||
Log in a user given a User supplied OTP received via mobile. | ||
|
||
* The verifyOtp method takes in different verification types. If a phone number is used, the type can either be sms or phone_change. If an email address is used, the type can be one of the following: signup, magiclink, recovery, invite or email_change. | ||
|
||
* The verification type used should be determined based on the corresponding auth method called before verifyOtp to sign up / sign-in a user. | ||
|
||
|
||
The RedwoodJS auth provider doesn't expose the `veriftyOtp` method from the Supabase SDK directly. | ||
|
||
Instead, since you always have access the the Supabase Auth client, you can access any method it exposes. | ||
|
||
So, in order to use the `verifyOtp` method, you would: | ||
|
||
```ts | ||
const { client } = useAuth() | ||
|
||
const { data, error } = await client.verifyOtp({ phone, token, type: 'sms'}) | ||
``` | ||
|
||
### Access the Supabase Auth Client | ||
|
||
Sometimes you may need to access the Supabase Auth client directly. | ||
|
||
```ts | ||
const { client } = useAuth() | ||
``` | ||
|
||
You can then use it to work with Supabase sessions, or auth events. | ||
|
||
|
||
### Retrieve a session | ||
|
||
Returns the session, refreshing it if necessary. The session returned can be null if the session is not detected which can happen in the event a user is not signed-in or has logged out. | ||
|
||
```ts | ||
const { client } = useAuth() | ||
|
||
const { data, error } = await client.getSession() | ||
``` | ||
|
||
### Listen to auth events | ||
|
||
Receive a notification every time an auth event happens. | ||
|
||
* Types of auth events: `SIGNED_IN`, `SIGNED_OUT`, `TOKEN_REFRESHED`, `USER_UPDATED`, `PASSWORD_RECOVERY` | ||
|
||
```ts | ||
const { client } = useAuth() | ||
|
||
client.onAuthStateChange((event, session) => { | ||
console.log(event, session) | ||
}) | ||
``` |
Oops, something went wrong.