Skip to content

Commit b31078d

Browse files
chore(readme): updated links in readme
1 parent 595db4f commit b31078d

File tree

1 file changed

+78
-78
lines changed

1 file changed

+78
-78
lines changed

README.md

Lines changed: 78 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ It Supports the following:
2424
## How to use
2525

2626
### Install the package (and remix-auth)
27-
* `yarn add remix-auth @afaik/remix-auth-supabase-strategy`
28-
* `pnpm install remix-auth @afaik/remix-auth-supabase-strategy`
29-
* `npm install remix-auth @afaik/remix-auth-supabase-strategy`
27+
* `yarn add remix-auth remix-auth-supabase`
28+
* `pnpm install remix-auth remix-auth-supabase`
29+
* `npm install remix-auth remix-auth-supabase`
3030

3131
### Breaking change v2 to v3
32-
To allow for more freedom and support some of the different authentication types the verify no longer just sends the form,
32+
To allow for more freedom and support some of the different authentication types the verify no longer just sends the form,
3333
but it now sends the entire request. See [Setup authenticator & strategy](#setup-authenticator-&-strategy)
3434

3535
### Setup sessionStorage
@@ -58,16 +58,16 @@ export const sessionStorage = createCookieSessionStorage({
5858
// app/auth.server.ts
5959
import type { Session } from '@supabase/supabase-js'
6060
import { Authenticator } from 'remix-auth'
61-
import { SupabaseStrategy } from '@afaik/remix-auth-supabase-strategy'
61+
import { SupabaseStrategy } from 'remix-auth-supabase'
6262
import { supabase } from '~/utils/supabase'
6363
import { sessionStorage } from '~/session.server'
6464

6565
export const supabaseStrategy = new SupabaseStrategy(
6666
{
67-
supabaseClient: supabase,
68-
sessionStorage,
69-
sessionKey: 'sb:session', // if not set, default is sb:session
70-
sessionErrorKey: 'sb:error', // if not set, default is sb:error
67+
supabaseClient: supabase,
68+
sessionStorage,
69+
sessionKey: 'sb:session', // if not set, default is sb:session
70+
sessionErrorKey: 'sb:error', // if not set, default is sb:error
7171
},
7272
async ({ req, supabaseClient }) => {
7373
// simple verify example for email/password auth
@@ -89,8 +89,8 @@ export const supabaseStrategy = new SupabaseStrategy(
8989
export const authenticator = new Authenticator<Session>(
9090
sessionStorage,
9191
{
92-
sessionKey: supabaseStrategy.sessionKey, // keep in sync
93-
sessionErrorKey: supabaseStrategy.sessionErrorKey, // keep in sync
92+
sessionKey: supabaseStrategy.sessionKey, // keep in sync
93+
sessionErrorKey: supabaseStrategy.sessionErrorKey, // keep in sync
9494
})
9595

9696
authenticator.use(supabaseStrategy)
@@ -101,10 +101,10 @@ authenticator.use(supabaseStrategy)
101101
102102
```js
103103
// app/routes/login.ts
104-
export const loader: LoaderFunction = async({ request }) =>
105-
supabaseStrategy.checkSession(request, {
106-
successRedirect: '/profile'
107-
})
104+
export const loader: LoaderFunction = async({ request }) =>
105+
supabaseStrategy.checkSession(request, {
106+
successRedirect: '/profile'
107+
})
108108

109109
export const action: ActionFunction = async({ request }) =>
110110
authenticator.authenticate('sb', request, {
@@ -113,47 +113,47 @@ export const action: ActionFunction = async({ request }) =>
113113
})
114114

115115
export default function LoginPage() {
116-
return (
117-
<Form method="post">
118-
<input type="email" name="email" />
119-
<input type="password" name="password" />
120-
<button>Sign In</button>
121-
</Form>
122-
);
116+
return (
117+
<Form method="post">
118+
<input type="email" name="email" />
119+
<input type="password" name="password" />
120+
<button>Sign In</button>
121+
</Form>
122+
);
123123
}
124124
```
125125
126126
```js
127127
// app/routes/profile.ts
128128
export const loader: LoaderFunction = async({ request }) => {
129-
// If token refresh and successRedirect not set, reload the current route
130-
const session = await supabaseStrategy.checkSession(request);
129+
// If token refresh and successRedirect not set, reload the current route
130+
const session = await supabaseStrategy.checkSession(request);
131131

132-
if (!session) {
133-
// If the user is not authenticated, you can do something or nothing
134-
// ⚠️ If you do nothing, /profile page is display
135-
}
132+
if (!session) {
133+
// If the user is not authenticated, you can do something or nothing
134+
// ⚠️ If you do nothing, /profile page is display
135+
}
136136
}
137137

138138
// Handle logout action
139139
export const action: ActionFunction = async({ request }) => {
140-
await authenticator.logout(request, { redirectTo: "/login" });
140+
await authenticator.logout(request, { redirectTo: "/login" });
141141
}
142142
```
143143
144144
##### Refresh token or redirect
145145
```js
146146
// If token is refreshing and successRedirect not set, it reloads the current route
147147
await supabaseStrategy.checkSession(request, {
148-
failureRedirect: "/login",
148+
failureRedirect: "/login",
149149
});
150150
```
151151
152152
##### Redirect if authenticated
153153
```js
154154
// If the user is authenticated, redirect to /profile
155155
await supabaseStrategy.checkSession(request, {
156-
successRedirect: "/profile",
156+
successRedirect: "/profile",
157157
});
158158
```
159159
@@ -163,9 +163,9 @@ await supabaseStrategy.checkSession(request, {
163163
// the result
164164
const session = await supabaseStrategy.checkSession(request);
165165
if (session) {
166-
// Here the user is authenticated
166+
// Here the user is authenticated
167167
} else {
168-
// Here the user is not authenticated
168+
// Here the user is not authenticated
169169
}
170170
```
171171
@@ -175,13 +175,13 @@ if (session) {
175175
```js
176176
// app/routes/login.ts
177177
export const loader: LoaderFunction = async({ request }) => {
178-
// Beware, never set failureRedirect equals to the current route
179-
const session = supabaseStrategy.checkSession(request, {
180-
successRedirect: '/profile',
181-
failureRedirect: "/login", // ❌ DONT'T : infinite loop
182-
});
183-
184-
// In this example, session is always null otherwise it would have been redirected
178+
// Beware, never set failureRedirect equals to the current route
179+
const session = supabaseStrategy.checkSession(request, {
180+
successRedirect: '/profile',
181+
failureRedirect: "/login", // ❌ DONT'T : infinite loop
182+
});
183+
184+
// In this example, session is always null otherwise it would have been redirected
185185
}
186186
```
187187
@@ -190,53 +190,53 @@ export const loader: LoaderFunction = async({ request }) => {
190190
```js
191191
// app/routes/profile.ts
192192
export const loader: LoaderFunction = async({ request }) =>
193-
// If checkSession fails, redirect to login and go back here when authenticated
194-
supabaseStrategy.checkSession(request, {
195-
failureRedirect: `/login?redirectTo=/profile`
196-
});
193+
// If checkSession fails, redirect to login and go back here when authenticated
194+
supabaseStrategy.checkSession(request, {
195+
failureRedirect: `/login?redirectTo=/profile`
196+
});
197197
```
198198
```js
199199
// app/routes/login.ts
200200
export const loader = async ({ request }) => {
201-
const redirectTo = new URL(request.url).searchParams.get("redirectTo") ?? "/dashboard";
201+
const redirectTo = new URL(request.url).searchParams.get("redirectTo") ?? "/dashboard";
202202

203-
return supabaseStrategy.checkSession(request, {
204-
successRedirect: redirectTo,
205-
});
203+
return supabaseStrategy.checkSession(request, {
204+
successRedirect: redirectTo,
205+
});
206206
};
207207

208208
export const action: ActionFunction = async({ request }) =>{
209-
// Always clone request when access formData() in action/loader with authenticator
210-
// 💡 request.formData() can't be called twice
211-
const data = await request.clone().formData();
212-
// If authenticate success, redirectTo what found in searchParams
213-
// Or where you want
214-
const redirectTo = data.get("redirectTo") ?? "/dashboard";
215-
216-
return authenticator.authenticate('sb', request, {
217-
successRedirect: redirectTo,
218-
failureRedirect: '/login',
219-
})
209+
// Always clone request when access formData() in action/loader with authenticator
210+
// 💡 request.formData() can't be called twice
211+
const data = await request.clone().formData();
212+
// If authenticate success, redirectTo what found in searchParams
213+
// Or where you want
214+
const redirectTo = data.get("redirectTo") ?? "/dashboard";
215+
216+
return authenticator.authenticate('sb', request, {
217+
successRedirect: redirectTo,
218+
failureRedirect: '/login',
219+
})
220220
}
221221

222222
export default function LoginPage() {
223-
const [searchParams] = useSearchParams();
224-
225-
return (
226-
<Form method="post">
227-
<input
228-
name="redirectTo"
229-
value={searchParams.get("redirectTo") ?? undefined}
230-
hidden
231-
readOnly
232-
/>
233-
<input type="email" name="email" required />
234-
<input
235-
type="password"
236-
name="password"
237-
/>
238-
<button>Sign In</button>
239-
</Form>
240-
);
223+
const [searchParams] = useSearchParams();
224+
225+
return (
226+
<Form method="post">
227+
<input
228+
name="redirectTo"
229+
value={searchParams.get("redirectTo") ?? undefined}
230+
hidden
231+
readOnly
232+
/>
233+
<input type="email" name="email" required />
234+
<input
235+
type="password"
236+
name="password"
237+
/>
238+
<button>Sign In</button>
239+
</Form>
240+
);
241241
}
242-
```
242+
```

0 commit comments

Comments
 (0)