@effectify/react-router-better-auth 0.4.0 → 0.4.1
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.
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
import { AuthService } from '@effectify/node-better-auth';
|
|
2
|
-
import { ActionArgsContext, LoaderArgsContext } from '@effectify/react-router';
|
|
2
|
+
import { ActionArgsContext, HttpResponse, LoaderArgsContext } from '@effectify/react-router';
|
|
3
3
|
import * as Effect from 'effect/Effect';
|
|
4
|
-
export
|
|
5
|
-
|
|
4
|
+
export interface AuthGuardOptions {
|
|
5
|
+
redirectOnFail?: string;
|
|
6
|
+
redirectInit?: ResponseInit;
|
|
7
|
+
}
|
|
8
|
+
type WithBetterAuthGuard = {
|
|
9
|
+
<A, E, L>(eff: Effect.Effect<A, E, LoaderArgsContext | AuthService.AuthContext | L>): Effect.Effect<A, E | AuthService.Unauthorized, LoaderArgsContext | AuthService.AuthServiceContext | L>;
|
|
10
|
+
with: (options: AuthGuardOptions) => <A, E, L>(eff: Effect.Effect<HttpResponse<A> | Response, E, LoaderArgsContext | AuthService.AuthContext | L>) => Effect.Effect<HttpResponse<A> | Response, E, LoaderArgsContext | AuthService.AuthServiceContext | L>;
|
|
11
|
+
};
|
|
12
|
+
export declare const withBetterAuthGuard: WithBetterAuthGuard;
|
|
13
|
+
type WithBetterAuthGuardAction = {
|
|
14
|
+
<A, E>(eff: Effect.Effect<A, E, ActionArgsContext | AuthService.AuthContext>): Effect.Effect<A, E | AuthService.Unauthorized, ActionArgsContext | AuthService.AuthServiceContext>;
|
|
15
|
+
with: (options: AuthGuardOptions) => <A, E>(eff: Effect.Effect<HttpResponse<A> | Response, E, ActionArgsContext | AuthService.AuthContext>) => Effect.Effect<HttpResponse<A> | Response, E, ActionArgsContext | AuthService.AuthServiceContext>;
|
|
16
|
+
};
|
|
17
|
+
export declare const withBetterAuthGuardAction: WithBetterAuthGuardAction;
|
|
18
|
+
export {};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { AuthService } from '@effectify/node-better-auth';
|
|
2
2
|
import { ActionArgsContext, LoaderArgsContext } from '@effectify/react-router';
|
|
3
3
|
import * as Effect from 'effect/Effect';
|
|
4
|
+
import { redirect } from 'react-router';
|
|
4
5
|
const mapHeaders = (args) => args.request.headers;
|
|
5
6
|
const verifySessionWithContext = (context) => Effect.gen(function* () {
|
|
6
7
|
const args = yield* context;
|
|
@@ -36,11 +37,19 @@ const verifySessionWithActionContext = (context) => Effect.gen(function* () {
|
|
|
36
37
|
});
|
|
37
38
|
const verifySession = () => verifySessionWithContext(LoaderArgsContext);
|
|
38
39
|
const verifySessionFromAction = () => verifySessionWithActionContext(ActionArgsContext);
|
|
39
|
-
export const withBetterAuthGuard = (
|
|
40
|
+
export const withBetterAuthGuard = Object.assign(((eff) => Effect.gen(function* () {
|
|
40
41
|
const authResult = yield* verifySession();
|
|
41
|
-
return yield* Effect.provideService(
|
|
42
|
+
return yield* Effect.provideService(eff, AuthService.AuthContext, authResult);
|
|
43
|
+
})), {
|
|
44
|
+
with: (opts) => (eff) => Effect.gen(function* () {
|
|
45
|
+
return yield* verifySession().pipe(Effect.flatMap((authResult) => Effect.provideService(eff, AuthService.AuthContext, authResult)), Effect.catchTag('Unauthorized', () => Effect.sync(() => redirect(opts.redirectOnFail, opts.redirectInit))));
|
|
46
|
+
}),
|
|
42
47
|
});
|
|
43
|
-
export const withBetterAuthGuardAction = (
|
|
48
|
+
export const withBetterAuthGuardAction = Object.assign(((eff) => Effect.gen(function* () {
|
|
44
49
|
const authResult = yield* verifySessionFromAction();
|
|
45
|
-
return yield* Effect.provideService(
|
|
50
|
+
return yield* Effect.provideService(eff, AuthService.AuthContext, authResult);
|
|
51
|
+
})), {
|
|
52
|
+
with: (opts) => (eff) => Effect.gen(function* () {
|
|
53
|
+
return yield* verifySessionFromAction().pipe(Effect.flatMap((authResult) => Effect.provideService(eff, AuthService.AuthContext, authResult)), Effect.catchTag('Unauthorized', () => Effect.sync(() => redirect(opts.redirectOnFail, opts.redirectInit))));
|
|
54
|
+
}),
|
|
46
55
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@effectify/react-router-better-auth",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "Integration of React Router + better-auth with Effect for React applications",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/src/index.js",
|
|
@@ -23,8 +23,8 @@
|
|
|
23
23
|
],
|
|
24
24
|
"peerDependencies": {
|
|
25
25
|
"effect": "3.19.13",
|
|
26
|
-
"@effectify/node-better-auth": "0.4.
|
|
27
|
-
"@effectify/react-router": "0.4.
|
|
26
|
+
"@effectify/node-better-auth": "0.4.9",
|
|
27
|
+
"@effectify/react-router": "0.4.9"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {},
|
|
30
30
|
"dependencies": {},
|