export const signIn = os
.input(SignInInput)
.output(SignInOutput)
.handler(async ({ input, context }) => {
const headers = (context as { headers?: Headers }).headers;
try {
const result = await Effect.runPromise(
Effect.gen(function* () {
const auth = yield* AuthService;
return yield* auth.signIn(input.email, input.password, headers);
}).pipe(Effect.provide(AuthService.layer))
);
return {
token: result.token,
user: {
id: result.user.id,
name: result.user.name,
// ... map other fields
},
};
} catch (error) {
const e = error as { _tag?: string; message?: string };
if (e._tag === "InvalidCredentialsError") {
throw new ORPCError("UNAUTHORIZED", { message: e.message });
}
if (e._tag === "AuthApiError") {
throw new ORPCError("INTERNAL_SERVER_ERROR", { message: e.message });
}
throw error;
}
});
export const signIn = os
.input(SignInInput)
.output(SignInOutput)
.handler(async ({ input, context }) => {
const headers = (context as { headers?: Headers }).headers;
try {
const result = await Effect.runPromise(
Effect.gen(function* () {
const auth = yield* AuthService;
return yield* auth.signIn(input.email, input.password, headers);
}).pipe(Effect.provide(AuthService.layer))
);
return {
token: result.token,
user: {
id: result.user.id,
name: result.user.name,
// ... map other fields
},
};
} catch (error) {
const e = error as { _tag?: string; message?: string };
if (e._tag === "InvalidCredentialsError") {
throw new ORPCError("UNAUTHORIZED", { message: e.message });
}
if (e._tag === "AuthApiError") {
throw new ORPCError("INTERNAL_SERVER_ERROR", { message: e.message });
}
throw error;
}
});