You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: packages/remix/README.md
+73-55Lines changed: 73 additions & 55 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,46 +7,37 @@
7
7
8
8
Check out our [developer docs](https://developer.slashid.dev/) for guides and API documentation.
9
9
10
-
## Setup
10
+
## Quick Start
11
11
12
-
### Prerequisites
12
+
`@slashid/remix` requires Remix v2.
13
13
14
-
You will need to [sign up to SlashID](https://console.slashid.dev/) and create an organization, once you've complete this you'll find your organization ID in [Settings -> General](https://console.slashid.dev/settings/general).
15
-
16
-
Your environment should have the following dependencies installed:
17
-
18
-
-`node.js` => `>=20.x.x`
19
-
-`react` => `>=18.x.x`
20
-
21
-
### Quick start
22
-
23
-
#### 1. Install `@slashid/remix`
14
+
You will need to [sign up to SlashID](https://console.slashid.dev/) and create an organization, once you've done this you'll find your organization ID in [Settings -> General](https://console.slashid.dev/settings/general).
24
15
16
+
### 1. Install `@slashid/remix`
25
17
Once you have a Remix application ready to go, you need to install the SlashID Remix SDK. This SDK provides a prebuilt log-in & sign-up form, control components and hooks - tailor made for Remix.
26
-
27
18
```
28
19
npm install @slashid/remix
29
20
```
30
21
31
-
#### 2. Create SlashID app primitives
32
-
22
+
### 2. Create SlashID app primitives
33
23
In your Remix application create a file `app/slashid.ts`.
34
24
35
25
In this file create the SlashID application primitives and re-export them, you'll use them later.
Tip: `oid` is your organization ID, you can find it in the [SlashID console](https://console.slashid.dev/) under [Settings -> General](https://console.slashid.dev/settings/general).
47
39
48
-
#### 3. Configure `slashIDRootLoader`
49
-
40
+
### 3. Configure `slashIDRootLoader`
50
41
To configure SlashID in your Remix application you'll need to update your root loader. With a small change you'll have easy access to authentication in all of your Remix routes.
51
42
52
43
Import the `slashIDRootLoader` you created in the previous step, invoke it and export it as `loader`.
#### 4. Wrap your application body with `<SlashIDApp>`
116
-
106
+
### 4. Wrap your application body with `<SlashIDApp>`
117
107
In step 2 you created `SlashIDApp`, it provides authentication state to your React component tree. There is no configuration, just add it to your Remix application.
118
108
119
109
```tsx
120
110
// root.tsx
121
111
122
-
import { SlashIDApp } from"~/slashid";
112
+
import { SlashIDApp } from'~/slashid'
123
113
124
114
exportdefaultfunction App() {
125
115
return (
@@ -144,16 +134,21 @@ export default function App() {
144
134
}
145
135
```
146
136
147
-
#### 5. Create your log-in/sign-up page
148
-
137
+
### 5. Create your log-in/sign-up page
149
138
SlashID offers a prebuilt form that works for both log-in and sign-up. Users with an account can log-in here and users without one need to simply complete the form to create their account.
@@ -166,10 +161,28 @@ export default function LogIn() {
166
161
}
167
162
```
168
163
169
-
#### 6. Protecting your pages
164
+
After the user has logged in, you might want to redirect them to another page. You can this with a loader.
170
165
171
-
##### Server side
166
+
When authentication has complete the form will tell the loader to run again, refreshing the authentication context, and triggering the redirect.
172
167
168
+
```tsx
169
+
// routes/login.tsx
170
+
171
+
import { slashIDLoader } from'~/slashid'
172
+
173
+
exportconst loader =slashIDLoader((args) => {
174
+
const user =getUser(args)
175
+
176
+
if (user) {
177
+
returnredirect("index") // redirect to your desired destination
178
+
}
179
+
180
+
return {}
181
+
})
182
+
```
183
+
### 6. Protecting your pages
184
+
185
+
#### Server side
173
186
To protect your routes you can use the `slashIDLoader` you created in step 2. This utility is a wrapper for your loaders that provides authentication state to your loader code.
174
187
175
188
You'll check if the user exists, and if not redirect them to the login page.
@@ -179,56 +192,61 @@ The `useSlashID()` hook provides authentication state & helper functions to your
SlashID has several [Control Components](https://developer.slashid.dev/docs/access/react-sdk/reference/components/react-sdk-reference-loggedin) that allow you to conditionally show or hide content based on the users authentication state.
211
225
212
226
You'll implement `<LoggedIn>`, `<LoggedOut>`, and provide the option to log-out by implementing the `logOut` helper function from the `useSlashID()` hook.
0 commit comments