refactor: ♻️emoves Env parameter
Removes the `Env` parameter from several functions to simplify their signatures and rely on the global `env` for configuration. This change reduces the number of arguments passed around, making the code cleaner and easier to maintain.
This commit is contained in:
@@ -4,7 +4,6 @@ import { env } from "hono/adapter";
|
||||
import { getAdminSdkCredentials } from "~/libs/gcloud/getAdminSdkCredentials";
|
||||
import { verifyFcmToken } from "~/libs/gcloud/verifyFcmToken";
|
||||
import { saveToken } from "~/models/token";
|
||||
import type { Env } from "~/types/env";
|
||||
import {
|
||||
ErrorResponse,
|
||||
ErrorResponseSchema,
|
||||
@@ -68,15 +67,12 @@ app.openapi(route, async (c) => {
|
||||
const { token, deviceId } = await c.req.json<typeof SaveTokenRequest._type>();
|
||||
|
||||
try {
|
||||
const isValidToken = await verifyFcmToken(
|
||||
token,
|
||||
getAdminSdkCredentials(c.env),
|
||||
);
|
||||
const isValidToken = await verifyFcmToken(token, getAdminSdkCredentials());
|
||||
if (!isValidToken) {
|
||||
return c.json(ErrorResponse, 401);
|
||||
}
|
||||
|
||||
await saveToken(env(c, "workerd"), deviceId, token);
|
||||
await saveToken(deviceId, token);
|
||||
} catch (error) {
|
||||
console.error("Failed to save token");
|
||||
console.error(error);
|
||||
|
||||
Reference in New Issue
Block a user