@slashid/remix 0.1.1 → 0.1.3

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/README.md CHANGED
@@ -1,4 +1,4 @@
1
- ![SlashID Remix SDK](./banner.png)
1
+ ![SlashID Remix SDK](https://raw.githubusercontent.com/slashid/javascript/main/packages/remix/banner.png)
2
2
 
3
3
  ![npm](https://img.shields.io/npm/v/@slashid/remix)
4
4
  ![build](https://github.com/slashid/javascript/actions/workflows/ci.yml/badge.svg)
@@ -7,25 +7,19 @@
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).
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).
15
15
 
16
- Your environment should have the following dependencies installed:
17
- - `node.js` => `>=20.x.x`
18
- - `react` => `>=18.x.x`
19
-
20
- ### Quick start
21
-
22
- #### 1. Install `@slashid/remix`
16
+ ### 1. Install `@slashid/remix`
23
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.
24
18
  ```
25
19
  npm install @slashid/remix
26
20
  ```
27
21
 
28
- #### 2. Create SlashID app primitives
22
+ ### 2. Create SlashID app primitives
29
23
  In your Remix application create a file `app/slashid.ts`.
30
24
 
31
25
  In this file create the SlashID application primitives and re-export them, you'll use them later.
@@ -43,7 +37,7 @@ export const {
43
37
  ```
44
38
  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).
45
39
 
46
- #### 3. Configure `slashIDRootLoader`
40
+ ### 3. Configure `slashIDRootLoader`
47
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.
48
42
 
49
43
  Import the `slashIDRootLoader` you created in the previous step, invoke it and export it as `loader`.
@@ -109,7 +103,7 @@ export const loader: LoaderFunction = slashIDRootLoader((args) => {
109
103
  });
110
104
  ```
111
105
 
112
- #### 4. Wrap your application body with `<SlashIDApp>`
106
+ ### 4. Wrap your application body with `<SlashIDApp>`
113
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.
114
108
 
115
109
  ```tsx
@@ -140,7 +134,7 @@ export default function App() {
140
134
  }
141
135
  ```
142
136
 
143
- #### 5. Create your log-in/sign-up page
137
+ ### 5. Create your log-in/sign-up page
144
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.
145
139
 
146
140
  ```tsx
@@ -166,9 +160,29 @@ export default function LogIn() {
166
160
  );
167
161
  }
168
162
  ```
169
- #### 6. Protecting your pages
170
163
 
171
- ##### Server side
164
+ After the user has logged in, you might want to redirect them to another page. You can this with a loader.
165
+
166
+ When authentication has complete the form will tell the loader to run again, refreshing the authentication context, and triggering the redirect.
167
+
168
+ ```tsx
169
+ // routes/login.tsx
170
+
171
+ import { slashIDLoader } from '~/slashid'
172
+
173
+ export const loader = slashIDLoader((args) => {
174
+ const user = getUser(args)
175
+
176
+ if (user) {
177
+ return redirect("index") // redirect to your desired destination
178
+ }
179
+
180
+ return {}
181
+ })
182
+ ```
183
+ ### 6. Protecting your pages
184
+
185
+ #### Server side
172
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.
173
187
 
174
188
  You'll check if the user exists, and if not redirect them to the login page.
@@ -206,7 +220,7 @@ export default function Index() {
206
220
  }
207
221
  ```
208
222
 
209
- ##### Client side
223
+ #### Client side
210
224
  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.