@effectify/react-router-better-auth 0.3.1 → 0.4.0
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,5 @@
|
|
|
1
1
|
import { AuthService } from '@effectify/node-better-auth';
|
|
2
|
-
import { ActionArgsContext,
|
|
2
|
+
import { ActionArgsContext, LoaderArgsContext } from '@effectify/react-router';
|
|
3
3
|
import * as Effect from 'effect/Effect';
|
|
4
|
-
export declare const
|
|
5
|
-
export declare const
|
|
4
|
+
export declare const withBetterAuthGuard: <A, E, L>(effect: Effect.Effect<A, E, LoaderArgsContext | AuthService.AuthContext | L>) => Effect.Effect<A, E | AuthService.Unauthorized, LoaderArgsContext | AuthService.AuthServiceContext | L>;
|
|
5
|
+
export declare const withBetterAuthGuardAction: <A, E>(effect: Effect.Effect<A, E, ActionArgsContext | AuthService.AuthContext>) => Effect.Effect<A, E | AuthService.Unauthorized, ActionArgsContext | AuthService.AuthServiceContext>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AuthService } from '@effectify/node-better-auth';
|
|
2
|
-
import { ActionArgsContext,
|
|
2
|
+
import { ActionArgsContext, LoaderArgsContext } from '@effectify/react-router';
|
|
3
3
|
import * as Effect from 'effect/Effect';
|
|
4
4
|
const mapHeaders = (args) => args.request.headers;
|
|
5
5
|
const verifySessionWithContext = (context) => Effect.gen(function* () {
|
|
@@ -14,7 +14,7 @@ const verifySessionWithContext = (context) => Effect.gen(function* () {
|
|
|
14
14
|
},
|
|
15
15
|
});
|
|
16
16
|
if (!session) {
|
|
17
|
-
return yield*
|
|
17
|
+
return yield* Effect.fail(new AuthService.Unauthorized({ details: 'Missing or invalid authentication' }));
|
|
18
18
|
}
|
|
19
19
|
return yield* Effect.succeed({ user: session.user, session: session.session });
|
|
20
20
|
});
|
|
@@ -30,23 +30,17 @@ const verifySessionWithActionContext = (context) => Effect.gen(function* () {
|
|
|
30
30
|
},
|
|
31
31
|
});
|
|
32
32
|
if (!session) {
|
|
33
|
-
return yield*
|
|
33
|
+
return yield* Effect.fail(new AuthService.Unauthorized({ details: 'Missing or invalid authentication' }));
|
|
34
34
|
}
|
|
35
35
|
return yield* Effect.succeed({ user: session.user, session: session.session });
|
|
36
36
|
});
|
|
37
37
|
const verifySession = () => verifySessionWithContext(LoaderArgsContext);
|
|
38
38
|
const verifySessionFromAction = () => verifySessionWithActionContext(ActionArgsContext);
|
|
39
|
-
export const
|
|
39
|
+
export const withBetterAuthGuard = (effect) => Effect.gen(function* () {
|
|
40
40
|
const authResult = yield* verifySession();
|
|
41
|
-
if (authResult instanceof HttpResponseFailure) {
|
|
42
|
-
return authResult;
|
|
43
|
-
}
|
|
44
41
|
return yield* Effect.provideService(effect, AuthService.AuthContext, authResult);
|
|
45
42
|
});
|
|
46
|
-
export const
|
|
43
|
+
export const withBetterAuthGuardAction = (effect) => Effect.gen(function* () {
|
|
47
44
|
const authResult = yield* verifySessionFromAction();
|
|
48
|
-
if (authResult instanceof HttpResponseFailure) {
|
|
49
|
-
return authResult;
|
|
50
|
-
}
|
|
51
45
|
return yield* Effect.provideService(effect, AuthService.AuthContext, authResult);
|
|
52
46
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@effectify/react-router-better-auth",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
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",
|
|
@@ -21,12 +21,12 @@
|
|
|
21
21
|
"dist",
|
|
22
22
|
"!**/*.tsbuildinfo"
|
|
23
23
|
],
|
|
24
|
-
"
|
|
25
|
-
"effect": "3.19.
|
|
26
|
-
"@effectify/
|
|
27
|
-
"@effectify/
|
|
24
|
+
"peerDependencies": {
|
|
25
|
+
"effect": "3.19.13",
|
|
26
|
+
"@effectify/node-better-auth": "0.4.7",
|
|
27
|
+
"@effectify/react-router": "0.4.7"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {},
|
|
30
|
-
"
|
|
30
|
+
"dependencies": {},
|
|
31
31
|
"optionalDependencies": {}
|
|
32
32
|
}
|