npm run fmt

This commit is contained in:
Abel Luck 2023-06-07 11:18:58 +00:00
parent 21fe35da05
commit 11c595619d
21 changed files with 155 additions and 137 deletions

View file

@ -1,5 +1,10 @@
/* eslint-disable unicorn/no-null */
import type { Adapter, AdapterAccount, AdapterSession, AdapterUser } from "next-auth/adapters";
import type {
Adapter,
AdapterAccount,
AdapterSession,
AdapterUser,
} from "next-auth/adapters";
import * as Wreck from "@hapi/wreck";
import * as Boom from "@hapi/boom";
@ -15,7 +20,7 @@ export interface Profile {
createdBy: string;
}
export type User = Profile & { id: string; createdAt: Date; updatedAt: Date; };
export type User = Profile & { id: string; createdAt: Date; updatedAt: Date };
export interface Session {
userId: string;
@ -103,7 +108,13 @@ export const MetamigoAdapter = (config: IAppConfig): Adapter => {
}
}
async function getUserByAccount({ providerAccountId, provider }: { providerAccountId: string, provider: string }) {
async function getUserByAccount({
providerAccountId,
provider,
}: {
providerAccountId: string;
provider: string;
}) {
try {
const { payload } = await wreck.get(
`getUserByAccount/${provider}/${providerAccountId}`
@ -112,7 +123,7 @@ export const MetamigoAdapter = (config: IAppConfig): Adapter => {
return payload;
} catch (error) {
if (Boom.isBoom(error, 404)) return null;
console.log(error)
console.log(error);
throw new Error("GET_USER_BY_ACCOUNT");
}
}
@ -129,12 +140,10 @@ export const MetamigoAdapter = (config: IAppConfig): Adapter => {
}
}
async function linkAccount(
account: AdapterAccount
) {
async function linkAccount(account: AdapterAccount) {
try {
await wreck.put("linkAccount", {payload: account} as any );
} catch(error) {
await wreck.put("linkAccount", { payload: account } as any);
} catch (error) {
console.log(error);
throw new Error("LINK_ACCOUNT_ERROR");
}
@ -142,25 +151,33 @@ export const MetamigoAdapter = (config: IAppConfig): Adapter => {
async function createSession(user: User) {
try {
const { payload }: {payload: AdapterSession} = await wreck.post("createSession", {
payload: user,
});
payload.expires = new Date(payload.expires)
const { payload }: { payload: AdapterSession } = await wreck.post(
"createSession",
{
payload: user,
}
);
payload.expires = new Date(payload.expires);
return payload;
} catch(error) {
console.log(error)
} catch (error) {
console.log(error);
throw new Error("CREATE_SESSION_ERROR");
}
}
async function getSessionAndUser(sessionToken: string) {
try {
const {payload}: {payload: any} = await wreck.get(`getSessionAndUser/${sessionToken}`);
const { session, user }: {session: AdapterSession, user: AdapterUser} = payload;
session.expires = new Date(session.expires)
return {session, user}
const { payload }: { payload: any } = await wreck.get(
`getSessionAndUser/${sessionToken}`
);
const {
session,
user,
}: { session: AdapterSession; user: AdapterUser } = payload;
session.expires = new Date(session.expires);
return { session, user };
} catch (error) {
console.log(error)
console.log(error);
if (Boom.isBoom(error, 404)) return null;
throw new Error("GET_SESSION_AND_USER_ERROR");
}