@effectify/react-router-better-auth 0.4.1 → 0.5.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.
package/dist/src/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
1
|
+
export * from "./lib/auth-guard.js";
|
|
2
|
+
export * from "./lib/handlers.js";
|
package/dist/src/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
1
|
+
export * from "./lib/auth-guard.js";
|
|
2
|
+
export * from "./lib/handlers.js";
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { AuthService } from
|
|
2
|
-
import { ActionArgsContext, HttpResponse, LoaderArgsContext } from
|
|
3
|
-
import * as Effect from
|
|
4
|
-
export
|
|
1
|
+
import { AuthService } from "@effectify/node-better-auth";
|
|
2
|
+
import { ActionArgsContext, type HttpResponse, LoaderArgsContext } from "@effectify/react-router";
|
|
3
|
+
import * as Effect from "effect/Effect";
|
|
4
|
+
export type AuthGuardOptions = {
|
|
5
5
|
redirectOnFail?: string;
|
|
6
6
|
redirectInit?: ResponseInit;
|
|
7
|
-
}
|
|
7
|
+
};
|
|
8
8
|
type WithBetterAuthGuard = {
|
|
9
|
-
<A, E,
|
|
10
|
-
with: (options: AuthGuardOptions) => <A, E,
|
|
9
|
+
<A, E, R>(eff: Effect.Effect<A, E, R>): Effect.Effect<A, E | AuthService.Unauthorized, Exclude<R, AuthService.AuthContext> | AuthService.AuthServiceContext | LoaderArgsContext>;
|
|
10
|
+
with: (options: AuthGuardOptions) => <A, E, R>(eff: Effect.Effect<HttpResponse<A> | Response, E, R>) => Effect.Effect<HttpResponse<A> | Response, E, Exclude<R, AuthService.AuthContext> | AuthService.AuthServiceContext | LoaderArgsContext>;
|
|
11
11
|
};
|
|
12
12
|
export declare const withBetterAuthGuard: WithBetterAuthGuard;
|
|
13
13
|
type WithBetterAuthGuardAction = {
|
|
14
|
-
<A, E>(eff: Effect.Effect<A, E,
|
|
15
|
-
with: (options: AuthGuardOptions) => <A, E>(eff: Effect.Effect<HttpResponse<A> | Response, E,
|
|
14
|
+
<A, E, R>(eff: Effect.Effect<A, E, R>): Effect.Effect<A, E | AuthService.Unauthorized, Exclude<R, AuthService.AuthContext> | AuthService.AuthServiceContext | ActionArgsContext>;
|
|
15
|
+
with: (options: AuthGuardOptions) => <A, E, R>(eff: Effect.Effect<HttpResponse<A> | Response, E, R>) => Effect.Effect<HttpResponse<A> | Response, E, Exclude<R, AuthService.AuthContext> | AuthService.AuthServiceContext | ActionArgsContext>;
|
|
16
16
|
};
|
|
17
17
|
export declare const withBetterAuthGuardAction: WithBetterAuthGuardAction;
|
|
18
18
|
export {};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { AuthService } from
|
|
2
|
-
import { ActionArgsContext, LoaderArgsContext } from
|
|
3
|
-
import * as Effect from
|
|
4
|
-
import { redirect } from
|
|
1
|
+
import { AuthService } from "@effectify/node-better-auth";
|
|
2
|
+
import { ActionArgsContext, LoaderArgsContext } from "@effectify/react-router";
|
|
3
|
+
import * as Effect from "effect/Effect";
|
|
4
|
+
import { redirect } from "react-router";
|
|
5
5
|
const mapHeaders = (args) => args.request.headers;
|
|
6
6
|
const verifySessionWithContext = (context) => Effect.gen(function* () {
|
|
7
7
|
const args = yield* context;
|
|
@@ -15,7 +15,7 @@ const verifySessionWithContext = (context) => Effect.gen(function* () {
|
|
|
15
15
|
},
|
|
16
16
|
});
|
|
17
17
|
if (!session) {
|
|
18
|
-
return yield* Effect.fail(new AuthService.Unauthorized({ details:
|
|
18
|
+
return yield* Effect.fail(new AuthService.Unauthorized({ details: "Missing or invalid authentication" }));
|
|
19
19
|
}
|
|
20
20
|
return yield* Effect.succeed({ user: session.user, session: session.session });
|
|
21
21
|
});
|
|
@@ -31,25 +31,25 @@ const verifySessionWithActionContext = (context) => Effect.gen(function* () {
|
|
|
31
31
|
},
|
|
32
32
|
});
|
|
33
33
|
if (!session) {
|
|
34
|
-
return yield* Effect.fail(new AuthService.Unauthorized({ details:
|
|
34
|
+
return yield* Effect.fail(new AuthService.Unauthorized({ details: "Missing or invalid authentication" }));
|
|
35
35
|
}
|
|
36
36
|
return yield* Effect.succeed({ user: session.user, session: session.session });
|
|
37
37
|
});
|
|
38
38
|
const verifySession = () => verifySessionWithContext(LoaderArgsContext);
|
|
39
39
|
const verifySessionFromAction = () => verifySessionWithActionContext(ActionArgsContext);
|
|
40
|
-
export const withBetterAuthGuard = Object.assign((
|
|
40
|
+
export const withBetterAuthGuard = Object.assign((eff) => Effect.gen(function* () {
|
|
41
41
|
const authResult = yield* verifySession();
|
|
42
42
|
return yield* Effect.provideService(eff, AuthService.AuthContext, authResult);
|
|
43
|
-
})
|
|
43
|
+
}), {
|
|
44
44
|
with: (opts) => (eff) => Effect.gen(function* () {
|
|
45
|
-
return yield* verifySession().pipe(Effect.flatMap((authResult) => Effect.provideService(eff, AuthService.AuthContext, authResult)), Effect.catchTag(
|
|
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
46
|
}),
|
|
47
47
|
});
|
|
48
|
-
export const withBetterAuthGuardAction = Object.assign((
|
|
48
|
+
export const withBetterAuthGuardAction = Object.assign((eff) => Effect.gen(function* () {
|
|
49
49
|
const authResult = yield* verifySessionFromAction();
|
|
50
50
|
return yield* Effect.provideService(eff, AuthService.AuthContext, authResult);
|
|
51
|
-
})
|
|
51
|
+
}), {
|
|
52
52
|
with: (opts) => (eff) => Effect.gen(function* () {
|
|
53
|
-
return yield* verifySessionFromAction().pipe(Effect.flatMap((authResult) => Effect.provideService(eff, AuthService.AuthContext, authResult)), Effect.catchTag(
|
|
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
54
|
}),
|
|
55
55
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AuthService } from
|
|
2
|
-
import { ActionArgsContext, LoaderArgsContext } from
|
|
3
|
-
import * as Effect from
|
|
1
|
+
import { AuthService } from "@effectify/node-better-auth";
|
|
2
|
+
import { ActionArgsContext, LoaderArgsContext } from "@effectify/react-router";
|
|
3
|
+
import * as Effect from "effect/Effect";
|
|
4
4
|
export declare const betterAuthLoader: Effect.Effect<Response, never, AuthService.AuthServiceContext | LoaderArgsContext>;
|
|
5
5
|
export declare const betterAuthAction: Effect.Effect<Response, never, AuthService.AuthServiceContext | ActionArgsContext>;
|
package/dist/src/lib/handlers.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { AuthService } from
|
|
2
|
-
import { ActionArgsContext, LoaderArgsContext } from
|
|
3
|
-
import * as Effect from
|
|
1
|
+
import { AuthService } from "@effectify/node-better-auth";
|
|
2
|
+
import { ActionArgsContext, LoaderArgsContext } from "@effectify/react-router";
|
|
3
|
+
import * as Effect from "effect/Effect";
|
|
4
4
|
const getRequest = (context) => Effect.map(context, (args) => args.request);
|
|
5
5
|
const getRequestFromAction = (context) => Effect.map(context, (args) => args.request);
|
|
6
6
|
const withAuthHandler = (requestEffect) => Effect.all([requestEffect, AuthService.AuthServiceContext]).pipe(Effect.andThen(([request, auth]) => Effect.gen(function* () {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@effectify/react-router-better-auth",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.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",
|
|
@@ -22,9 +22,9 @@
|
|
|
22
22
|
"!**/*.tsbuildinfo"
|
|
23
23
|
],
|
|
24
24
|
"peerDependencies": {
|
|
25
|
-
"effect": "3.19.
|
|
26
|
-
"@effectify/
|
|
27
|
-
"@effectify/
|
|
25
|
+
"effect": "3.19.15",
|
|
26
|
+
"@effectify/react-router": "0.5.0",
|
|
27
|
+
"@effectify/node-better-auth": "0.5.0"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {},
|
|
30
30
|
"dependencies": {},
|