feat: add effect api
This commit is contained in:
@@ -11,9 +11,9 @@ import {
|
||||
} from "effect";
|
||||
import { FileSystem } from "@effect/platform";
|
||||
import { config } from "./config";
|
||||
import { AuthState } from "./schema";
|
||||
import { authClient } from "@/lib/auth-client";
|
||||
import type { BetterFetchResponse } from "@better-fetch/fetch";
|
||||
import { AuthSchema } from "@money/shared/auth";
|
||||
|
||||
class AuthClientUnknownError extends Data.TaggedError(
|
||||
"AuthClientUnknownError",
|
||||
@@ -129,7 +129,7 @@ const pollToken = ({ device_code }: { device_code: string }) =>
|
||||
const getFromFromDisk = Effect.gen(function* () {
|
||||
const fs = yield* FileSystem.FileSystem;
|
||||
const content = yield* fs.readFileString(config.authPath);
|
||||
const auth = yield* Schema.decode(Schema.parseJson(AuthState))(content);
|
||||
const auth = yield* Schema.decode(Schema.parseJson(AuthSchema))(content);
|
||||
if (auth.session.expiresAt < new Date())
|
||||
yield* Effect.fail(new AuthClientExpiredToken());
|
||||
return auth;
|
||||
@@ -160,7 +160,7 @@ const requestAuth = Effect.gen(function* () {
|
||||
);
|
||||
if (sessionData == null) return yield* Effect.fail(new AuthClientNoData());
|
||||
|
||||
const result = yield* Schema.decodeUnknown(AuthState)(sessionData);
|
||||
const result = yield* Schema.decodeUnknown(AuthSchema)(sessionData);
|
||||
|
||||
const fs = yield* FileSystem.FileSystem;
|
||||
yield* fs.writeFileString(config.authPath, JSON.stringify(result));
|
||||
|
||||
Reference in New Issue
Block a user