Skip to content

Commit

Permalink
chore: format repository
Browse files Browse the repository at this point in the history
  • Loading branch information
dev-xo committed Dec 16, 2023
1 parent 3e4f44e commit 121a0f2
Show file tree
Hide file tree
Showing 16 changed files with 504 additions and 498 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ module.exports = {
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'],
extends: ['plugin:@typescript-eslint/recommended', 'prettier'],
}
};
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@ node_modules
/coverage

# Miscellaneous.
TODO.md
TODO.md

# Prettier Format.
1 change: 1 addition & 0 deletions .husky/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
### Prettier Format.
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"tabWidth": 2,
"printWidth": 90,
"semi": false,
"semi": true,
"useTabs": false,
"bracketSpacing": true,
"bracketSameLine": true,
Expand Down
22 changes: 11 additions & 11 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,23 @@ diverse, inclusive, and healthy community.
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,
- 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
- 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
- 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
- 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
- Other conduct which could reasonably be considered inappropriate in a
professional setting

## Enforcement Responsibilities
Expand Down Expand Up @@ -106,7 +106,7 @@ Violating these terms may lead to a permanent ban.
### 4. Permanent Ban

**Community Impact**: Demonstrating a pattern of violation of community
standards, including sustained inappropriate behavior, harassment of an
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
Expand Down
62 changes: 31 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,11 @@ We'll require an Email Service to send the codes to our users. Feel free to use
```ts
export type SendEmailBody = {
to: string | string[]
subject: string
html: string
text?: string
}
to: string | string[];
subject: string;
html: string;
text?: string;
};

export async function sendEmail(body: SendEmailBody) {
return fetch(`https://any-email-service.com`, {
Expand All @@ -118,7 +118,7 @@ export async function sendEmail(body: SendEmailBody) {
'Content-Type': 'application/json',
},
body: JSON.stringify({ ...body }),
})
});
}
```
Expand All @@ -133,7 +133,7 @@ Implement the following code and replace the `secrets` property with a strong st
```ts
// app/modules/auth/session.server.ts
import { createCookieSessionStorage } from '@remix-run/node'
import { createCookieSessionStorage } from '@remix-run/node';

export const sessionStorage = createCookieSessionStorage({
cookie: {
Expand All @@ -144,9 +144,9 @@ export const sessionStorage = createCookieSessionStorage({
secrets: [process.env.SESSION_SECRET || 'NOT_A_STRONG_SECRET'],
secure: process.env.NODE_ENV === 'production',
},
})
});

export const { getSession, commitSession, destroySession } = sessionStorage
export const { getSession, commitSession, destroySession } = sessionStorage;
```
## Strategy Instance
Expand All @@ -160,22 +160,22 @@ Implement the following code and replace the `secret` property with a strong str
```ts
// app/modules/auth/auth.server.ts
import { Authenticator } from 'remix-auth'
import { TOTPStrategy } from 'remix-auth-totp'
import { Authenticator } from 'remix-auth';
import { TOTPStrategy } from 'remix-auth-totp';

import { sessionStorage } from './session.server'
import { sendEmail } from './email.server'
import { db } from '~/db'
import { sessionStorage } from './session.server';
import { sendEmail } from './email.server';
import { db } from '~/db';

// The User type should match the one from database.
type User = {
id: string
email: string
}
id: string;
email: string;
};

export let authenticator = new Authenticator<User>(sessionStorage, {
throwOnError: true,
})
});

authenticator.use(
new TOTPStrategy(
Expand All @@ -187,7 +187,7 @@ authenticator.use(
},
async ({ email, code, form, magicLink, request }) => {},
),
)
);
```
> [!NOTE]
Expand Down Expand Up @@ -251,26 +251,26 @@ authenticator.use(
async ({ email, code, magicLink, form, request }) => {
// You can determine whether the user is authenticating
// via OTP code submission or Magic-Link URL and run your own logic.
if (form) console.log('Optional form submission logic.')
if (magicLink) console.log('Optional magic-link submission logic.')
if (form) console.log('Optional form submission logic.');
if (magicLink) console.log('Optional magic-link submission logic.');

// Get user from database.
let user = await db.user.findFirst({
where: { email },
})
});

// Create a new user if it doesn't exist.
if (!user) {
user = await db.user.create({
data: { email },
})
});
}

// Return user as Session.
return user
return user;
},
),
)
);
```
## Auth Routes
Expand Down Expand Up @@ -401,28 +401,28 @@ export default function Account() {
```tsx
// app/routes/magic-link.tsx
import type { DataFunctionArgs } from '@remix-run/node'
import { authenticator } from '~/modules/auth/auth.server'
import type { DataFunctionArgs } from '@remix-run/node';
import { authenticator } from '~/modules/auth/auth.server';

export async function loader({ request }: DataFunctionArgs) {
await authenticator.authenticate('TOTP', request, {
successRedirect: '/account',
failureRedirect: '/login',
})
});
}
```
### `logout.tsx`
```tsx
// app/routes/logout.tsx
import type { DataFunctionArgs } from '@remix-run/node'
import { authenticator } from '~/modules/auth/auth.server'
import type { DataFunctionArgs } from '@remix-run/node';
import { authenticator } from '~/modules/auth/auth.server';

export async function action({ request }: DataFunctionArgs) {
return await authenticator.logout(request, {
redirectTo: '/',
})
});
}
```
Expand Down
2 changes: 2 additions & 0 deletions SECURITY.MD
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@
## Reporting a Vulnerability

In case of a vulnerability please reach out to active maintainers of the project and report it to them.

## Prettier Format
44 changes: 22 additions & 22 deletions docs/customization.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ authenticator.use(
// ...
},
}),
)
);
```

### TOTP Generation
Expand All @@ -31,32 +31,32 @@ export interface TOTPGenerationOptions {
* It should be Base32 encoded (Feel free to use: https://npm.im/thirty-two).
* @default Random Base32 secret.
*/
secret?: string
secret?: string;
/**
* The algorithm used to generate the OTP.
* @default 'SHA1'
*/
algorithm?: string
algorithm?: string;
/**
* The character set used to generate the OTP.
* @default 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
*/
charSet?: string
charSet?: string;
/**
* The number of digits the OTP will have.
* @default 6
*/
digits?: number
digits?: number;
/**
* The number of seconds the OTP will be valid.
* @default 60
*/
period?: number
period?: number;
/**
* The number of attempts the user has to verify the OTP.
* @default 3
*/
maxAttempts: number
maxAttempts: number;
}

authenticator.use(
Expand All @@ -67,7 +67,7 @@ authenticator.use(
// ...
},
}),
)
);
```

### Magic Link Generation
Expand All @@ -83,18 +83,18 @@ export interface MagicLinkGenerationOptions {
* Whether to enable the Magic Link generation.
* @default true
*/
enabled?: boolean
enabled?: boolean;
/**
* The host URL for the Magic Link.
* If omitted, it will be inferred from the request.
* @default undefined
*/
hostUrl?: string
hostUrl?: string;
/**
* The callback path for the Magic Link.
* @default '/magic-link'
*/
callbackPath?: string
callbackPath?: string;
}
```

Expand All @@ -109,19 +109,19 @@ export interface CustomErrorsOptions {
/**
* The required email error message.
*/
requiredEmail?: string
requiredEmail?: string;
/**
* The invalid email error message.
*/
invalidEmail?: string
invalidEmail?: string;
/**
* The invalid TOTP error message.
*/
invalidTotp?: string
invalidTotp?: string;
/**
* The inactive TOTP error message.
*/
inactiveTotp?: string
inactiveTotp?: string;
}

authenticator.use(
Expand All @@ -130,7 +130,7 @@ authenticator.use(
requiredEmail: 'Whoops, email is required.',
},
}),
)
);
```

### More Options
Expand All @@ -142,32 +142,32 @@ export interface TOTPStrategyOptions<User> {
/**
* The secret used to encrypt the session.
*/
secret: string
secret: string;
/**
* The maximum age of the session in milliseconds.
* @default undefined
*/
maxAge?: number
maxAge?: number;
/**
* The form input name used to get the email address.
* @default "email"
*/
emailFieldKey?: string
emailFieldKey?: string;
/**
* The form input name used to get the TOTP.
* @default "totp"
*/
totpFieldKey?: string
totpFieldKey?: string;
/**
* The session key that stores the email address.
* @default "auth:email"
*/
sessionEmailKey?: string
sessionEmailKey?: string;
/**
* The session key that stores the encrypted TOTP.
* @default "auth:totp"
*/
sessionTotpKey?: string
sessionTotpKey?: string;
}
```

Expand Down
Loading

0 comments on commit 121a0f2

Please sign in to comment.