Skip to content

Commit

Permalink
apply prettier on everything (thirdweb-dev#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
joaquim-verges authored Sep 8, 2022
1 parent 8a5501f commit 8aef97d
Show file tree
Hide file tree
Showing 87 changed files with 720 additions and 689 deletions.
5 changes: 4 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
lib
node_modules
node_modules
dist
contracts-js
*.d.ts
30 changes: 15 additions & 15 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ We pledge to act and interact in ways that contribute to an open, welcoming, div

Examples of behavior that contributes to a positive environment for our community include:

* Demonstrating empathy and kindness toward other people
* Being respectful of differing opinions, viewpoints, and experiences
* Giving and gracefully accepting constructive feedback
* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
* Focusing on what is best not just for us as individuals, but for the overall community
- Demonstrating empathy and kindness toward other people
- Being respectful of differing opinions, viewpoints, and experiences
- Giving and gracefully accepting constructive feedback
- Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
- Focusing on what is best not just for us as individuals, but for the overall community

Examples of unacceptable behavior include:

* The use of sexualized language or imagery, and sexual attention or advances of any kind
* Trolling, insulting or derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or email address, without their explicit permission
* Other conduct which could reasonably be considered inappropriate in a professional setting
- The use of sexualized language or imagery, and sexual attention or advances of any kind
- Trolling, insulting or derogatory comments, and personal or political attacks
- Public or private harassment
- Publishing others' private information, such as a physical or email address, without their explicit permission
- Other conduct which could reasonably be considered inappropriate in a professional setting

## Enforcement Responsibilities

Expand Down Expand Up @@ -64,20 +64,20 @@ Community leaders will follow these Community Impact Guidelines in determining t

### 4. Permanent Ban

**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.

**Consequence**: A permanent ban from any sort of public interaction within the community.

## Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0, available at [https://www.contributor-covenant.org/version/2/0/code_of_conduct.html][v2.0].

Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder][Mozilla CoC].
Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder][mozilla coc].

For answers to common questions about this code of conduct, see the FAQ at [https://www.contributor-covenant.org/faq][FAQ]. Translations are available at [https://www.contributor-covenant.org/translations][translations].
For answers to common questions about this code of conduct, see the FAQ at [https://www.contributor-covenant.org/faq][faq]. Translations are available at [https://www.contributor-covenant.org/translations][translations].

[homepage]: https://www.contributor-covenant.org
[v2.0]: https://www.contributor-covenant.org/version/2/0/code_of_conduct.html
[Mozilla CoC]: https://github.com/mozilla/diversity
[FAQ]: https://www.contributor-covenant.org/faq
[mozilla coc]: https://github.com/mozilla/diversity
[faq]: https://www.contributor-covenant.org/faq
[translations]: https://www.contributor-covenant.org/translations
1 change: 1 addition & 0 deletions packages/auth/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Install the latest version of the SDK with either `npm` or `yarn`:
```shell
npm install @thirdweb-dev/auth @thirdweb-dev/sdk ethers
```

```shell
yarn add @thirdweb-dev/auth @thirdweb-dev/sdk ethers
```
4 changes: 2 additions & 2 deletions packages/auth/src/express/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ export function ThirdwebAuth(app: Express, cfg: ThirdwebAuthConfig) {
if (token) {
try {
const address = await sdk.auth.authenticate(domain, token);

if (ctx.callbacks?.user) {
user = await ctx.callbacks.user(address);
}

user = { ...user, address };
} catch {
// No-op
Expand Down
4 changes: 2 additions & 2 deletions packages/auth/src/express/routes/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function redirectWithError(req: Request, res: Response, error: string) {
export default async function handler(
req: Request,
res: Response,
ctx: ThirdwebAuthContext
ctx: ThirdwebAuthContext,
) {
if (req.method !== "GET") {
return redirectWithError(req, res, "INVALID_METHOD");
Expand Down Expand Up @@ -44,7 +44,7 @@ export default async function handler(
httpOnly: true,
secure: true,
sameSite: "strict",
})
}),
);

if (ctx.callbacks?.login) {
Expand Down
2 changes: 1 addition & 1 deletion packages/auth/src/express/routes/logout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default async function handler(req: Request, res: Response) {
serialize("thirdweb_auth_token", "", {
path: "/",
expires: new Date(Date.now() + 5 * 1000),
})
}),
);

return res.status(301).redirect(req.headers.referer as string);
Expand Down
2 changes: 1 addition & 1 deletion packages/auth/src/express/routes/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ export default async function handler(req: Request, res: Response) {
error: "Invalid method. Only GET supported.",
});
}

return res.status(200).json(req.user);
}
16 changes: 12 additions & 4 deletions packages/auth/src/express/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,25 @@ export type ThirdwebAuthConfig = {
domain: string;
authUrl?: string;
callbacks?: {
login?: (address: string) => (Promise<void> | void);
user?: (address: string) => (Promise<Omit<ThirdwebAuthUser, "address">> | Omit<ThirdwebAuthUser, "address">);
login?: (address: string) => Promise<void> | void;
user?: (
address: string,
) =>
| Promise<Omit<ThirdwebAuthUser, "address">>
| Omit<ThirdwebAuthUser, "address">;
};
};

export type ThirdwebAuthContext = {
sdk: ThirdwebSDK;
domain: string;
callbacks?: {
login?: (address: string) => (Promise<void> | void);
user?: (address: string) => (Promise<Omit<ThirdwebAuthUser, "address">> | Omit<ThirdwebAuthUser, "address">);
login?: (address: string) => Promise<void> | void;
user?: (
address: string,
) =>
| Promise<Omit<ThirdwebAuthUser, "address">>
| Omit<ThirdwebAuthUser, "address">;
};
};

Expand Down
76 changes: 41 additions & 35 deletions packages/auth/src/next-auth/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
import { ThirdwebNextAuthConfig } from "./types";
import { ThirdwebSDK } from "@thirdweb-dev/sdk";
import { serialize } from "cookie";
import { GetServerSidePropsContext, NextApiRequest, NextApiResponse } from "next";
import NextAuth, { NextAuthOptions, Session, unstable_getServerSession } from "next-auth";
import {
GetServerSidePropsContext,
NextApiRequest,
NextApiResponse,
} from "next";
import NextAuth, {
NextAuthOptions,
Session,
unstable_getServerSession,
} from "next-auth";
import CredentialsProvider from "next-auth/providers/credentials";

export function ThirdwebNextAuth(cfg: ThirdwebNextAuthConfig) {
Expand All @@ -21,10 +29,7 @@ export function ThirdwebNextAuth(cfg: ThirdwebNextAuthConfig) {
async authorize({ payload }: any) {
try {
const parsed = JSON.parse(payload);
const token = await sdk.auth.generateAuthToken(
cfg.domain,
parsed
);
const token = await sdk.auth.generateAuthToken(cfg.domain, parsed);
const address = await sdk.auth.authenticate(cfg.domain, token);

// Securely set httpOnly cookie on request to prevent XSS on frontend
Expand All @@ -36,7 +41,7 @@ export function ThirdwebNextAuth(cfg: ThirdwebNextAuthConfig) {
httpOnly: true,
secure: true,
sameSite: "strict",
})
}),
);

return { address };
Expand All @@ -47,11 +52,10 @@ export function ThirdwebNextAuth(cfg: ThirdwebNextAuthConfig) {
});
}

function nextOptions (
req: GetServerSidePropsContext["req"],
res: GetServerSidePropsContext["res"]
function nextOptions(
req: GetServerSidePropsContext["req"],
res: GetServerSidePropsContext["res"],
): NextAuthOptions {

async function session({ session }: { session: Session }) {
const token = req.cookies.thirdweb_auth_token || "";
try {
Expand All @@ -69,35 +73,35 @@ export function ThirdwebNextAuth(cfg: ThirdwebNextAuthConfig) {
serialize("thirdweb_auth_token", "", {
path: "/",
expires: new Date(Date.now() + 5 * 1000),
})
}),
);
}

const providers: NextAuthOptions["providers"] = [
...cfg.nextOptions.providers,
ThirdwebProvider(res),
]
];

const configSession = cfg.nextOptions.callbacks?.session
const configSession = cfg.nextOptions.callbacks?.session;
const callbacks: NextAuthOptions["callbacks"] = {
...cfg.nextOptions.callbacks,
session: configSession
session: configSession
? async (params) => {
params.session = await session(params);
return configSession(params);
}
: session
params.session = await session(params);
return configSession(params);
}
: session,
};

const configSignOut = cfg.nextOptions.events?.signOut
const configSignOut = cfg.nextOptions.events?.signOut;
const events: NextAuthOptions["events"] = {
...cfg.nextOptions.events,
signOut: configSignOut
? async (params) => {
signOut();
return configSignOut(params);
}
: signOut
signOut();
return configSignOut(params);
}
: signOut,
};

return {
Expand All @@ -106,30 +110,32 @@ export function ThirdwebNextAuth(cfg: ThirdwebNextAuthConfig) {
callbacks,
events,
};
};
}

async function getUser(
...args:
| [NextApiRequest, NextApiResponse]
...args:
| [NextApiRequest, NextApiResponse]
| [GetServerSidePropsContext["req"], GetServerSidePropsContext["res"]]
) {
return unstable_getServerSession(args[0], args[1], nextOptions(args[0], args[1]));
return unstable_getServerSession(
args[0],
args[1],
nextOptions(args[0], args[1]),
);
}

function NextAuthHandler(
...args: [] | [NextApiRequest, NextApiResponse]
) {
function NextAuthHandler(...args: [] | [NextApiRequest, NextApiResponse]) {
if (args.length === 0) {
return (req: NextApiRequest, res: NextApiResponse) => {
return NextAuth(req, res, nextOptions(req, res));
}
};
}

return NextAuth(args[0], args[1], nextOptions(args[0], args[1]));
}

return {
NextAuthHandler,
getUser
}
}
getUser,
};
}
2 changes: 1 addition & 1 deletion packages/auth/src/next-auth/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ export type ThirdwebNextAuthConfig = {
privateKey: string;
domain: string;
nextOptions: NextAuthOptions;
}
};
4 changes: 2 additions & 2 deletions packages/auth/src/next/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export * from "./types";
async function ThirdwebAuthRouter(
req: NextApiRequest,
res: NextApiResponse,
ctx: ThirdwebAuthContext
ctx: ThirdwebAuthContext,
) {
// Catch-all route must be named with [...thirdweb]
const { thirdweb } = req.query;
Expand Down Expand Up @@ -58,7 +58,7 @@ export function ThirdwebAuth(cfg: ThirdwebAuthConfig) {
}

async function getUser(
req: GetServerSidePropsContext["req"] | NextRequest | NextApiRequest
req: GetServerSidePropsContext["req"] | NextRequest | NextApiRequest,
) {
const { sdk, domain } = ctx;
let user: ThirdwebAuthUser | null = null;
Expand Down
6 changes: 3 additions & 3 deletions packages/auth/src/next/routes/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { NextApiRequest, NextApiResponse } from "next";
function redirectWithError(
req: NextApiRequest,
res: NextApiResponse,
error: string
error: string,
) {
const encodedError = encodeURIComponent(error);
const url = new URL(req.headers.referer as string);
Expand All @@ -17,7 +17,7 @@ function redirectWithError(
export default async function handler(
req: NextApiRequest,
res: NextApiResponse,
ctx: ThirdwebAuthContext
ctx: ThirdwebAuthContext,
) {
if (req.method !== "GET") {
return redirectWithError(req, res, "INVALID_METHOD");
Expand Down Expand Up @@ -48,7 +48,7 @@ export default async function handler(
httpOnly: true,
secure: true,
sameSite: "strict",
})
}),
);

if (ctx.callbacks?.login) {
Expand Down
4 changes: 2 additions & 2 deletions packages/auth/src/next/routes/logout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { NextApiRequest, NextApiResponse } from "next";

export default async function handler(
req: NextApiRequest,
res: NextApiResponse
res: NextApiResponse,
) {
if (req.method !== "GET") {
return res.status(400).json({
Expand All @@ -17,7 +17,7 @@ export default async function handler(
serialize("thirdweb_auth_token", "", {
path: "/",
expires: new Date(Date.now() + 5 * 1000),
})
}),
);

return res.status(301).redirect(req.headers.referer as string);
Expand Down
4 changes: 2 additions & 2 deletions packages/auth/src/next/routes/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import { NextApiRequest, NextApiResponse } from "next";
export default async function handler(
req: NextApiRequest,
res: NextApiResponse,
ctx: ThirdwebAuthContext
ctx: ThirdwebAuthContext,
) {
if (req.method !== "GET") {
return res.status(400).json({
error: "Invalid method. Only GET supported.",
});
}

const { sdk, domain } = ctx;
let user = null;
const token = req.cookies.thirdweb_auth_token;
Expand Down
Loading

0 comments on commit 8aef97d

Please sign in to comment.