Skip to content

Commit d97bfcb

Browse files
committed
02/02: fix svg import build error
1 parent 4834b84 commit d97bfcb

File tree

9 files changed

+6603
-9154
lines changed

9 files changed

+6603
-9154
lines changed
Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1 @@
1-
# Two-factor authentication
2-
3-
- How to test authentication flows that require Two-Factor Authentication (i.e. OTP).
4-
- Comes _after_ authentication personas because this is essentially testing a persona-dependent behavior (a user _who has 2FA enabled_ is able to log in into the app).
1+
# Passkeys

exercises/02.authentication/02.solution.2fa/app/routes/_auth+/auth.$provider.callback.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { GITHUB_PROVIDER_NAME } from '#app/utils/connections.tsx'
99
import { prisma } from '#app/utils/db.server.ts'
1010
import { authSessionStorage } from '#app/utils/session.server.ts'
1111
import { generateTOTP } from '#app/utils/totp.server.ts'
12-
import { createUser } from '#tests/db-utils.ts'
12+
import { generateUserInfo } from '#tests/db-utils.ts'
1313
import { insertGitHubUser, deleteGitHubUsers } from '#tests/mocks/github.ts'
1414
import { server } from '#tests/mocks/index.ts'
1515
import { consoleError } from '#tests/setup/setup-test-env.ts'
@@ -109,7 +109,7 @@ test(`when a user is logged in and has already connected, it doesn't do anything
109109
test('when a user exists with the same email, create connection and make session', async () => {
110110
const githubUser = await insertGitHubUser()
111111
const email = githubUser.primaryEmail.toLowerCase()
112-
const { userId } = await setupUser({ ...createUser(), email })
112+
const { userId } = await setupUser({ ...generateUserInfo(), email })
113113
const request = await setupRequest({ code: githubUser.code })
114114
const response = await loader({ request, params: PARAMS, context: {} })
115115

@@ -141,7 +141,7 @@ test('gives an error if the account is already connected to another user', async
141141
const githubUser = await insertGitHubUser()
142142
await prisma.user.create({
143143
data: {
144-
...createUser(),
144+
...generateUserInfo(),
145145
connections: {
146146
create: {
147147
providerName: GITHUB_PROVIDER_NAME,
@@ -245,7 +245,7 @@ async function setupRequest({
245245
return request
246246
}
247247

248-
async function setupUser(userData = createUser()) {
248+
async function setupUser(userData = generateUserInfo()) {
249249
const session = await prisma.session.create({
250250
data: {
251251
expirationDate: getSessionExpirationDate(),

exercises/02.authentication/02.solution.2fa/app/routes/users+/$username.test.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { loader as rootLoader } from '#app/root.tsx'
1010
import { getSessionExpirationDate, sessionKey } from '#app/utils/auth.server.ts'
1111
import { prisma } from '#app/utils/db.server.ts'
1212
import { authSessionStorage } from '#app/utils/session.server.ts'
13-
import { createUser, getUserImages } from '#tests/db-utils.ts'
13+
import { generateUserInfo, getUserImages } from '#tests/db-utils.ts'
1414
import { default as UsernameRoute, loader } from './$username.tsx'
1515

1616
test('The user profile when not logged in as self', async () => {
@@ -19,7 +19,7 @@ test('The user profile when not logged in as self', async () => {
1919
userImages[faker.number.int({ min: 0, max: userImages.length - 1 })]
2020
const user = await prisma.user.create({
2121
select: { id: true, username: true, name: true },
22-
data: { ...createUser(), image: { create: userImage } },
22+
data: { ...generateUserInfo(), image: { create: userImage } },
2323
})
2424
const App = createRoutesStub([
2525
{
@@ -44,7 +44,7 @@ test('The user profile when logged in as self', async () => {
4444
userImages[faker.number.int({ min: 0, max: userImages.length - 1 })]
4545
const user = await prisma.user.create({
4646
select: { id: true, username: true, name: true },
47-
data: { ...createUser(), image: { create: userImage } },
47+
data: { ...generateUserInfo(), image: { create: userImage } },
4848
})
4949
const session = await prisma.session.create({
5050
select: { id: true },

exercises/02.authentication/02.solution.2fa/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,13 @@
145145
"jsdom": "^25.0.1",
146146
"msw": "^2.7.6",
147147
"npm-run-all": "^4.1.5",
148-
"playwright-persona": "^0.2.6",
148+
"playwright-persona": "^0.2.5",
149149
"prettier": "^3.5.3",
150150
"prettier-plugin-sql": "^0.19.0",
151151
"prettier-plugin-tailwindcss": "^0.6.11",
152152
"react-router-devtools": "^5.0.5",
153153
"remix-flat-routes": "^0.8.5",
154+
"test-passkey": "^1.0.1",
154155
"tsx": "^4.19.4",
155156
"tw-animate-css": "^1.2.9",
156157
"typescript": "^5.8.3",

exercises/02.authentication/02.solution.2fa/prisma/seed.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { prisma } from '#app/utils/db.server.ts'
33
import { MOCK_CODE_GITHUB } from '#app/utils/providers/constants'
44
import {
55
createPassword,
6-
createUser,
6+
generateUserInfo,
77
getNoteImages,
88
getUserImages,
99
} from '#tests/db-utils.ts'
@@ -19,7 +19,7 @@ async function seed() {
1919
const userImages = await getUserImages()
2020

2121
for (let index = 0; index < totalUsers; index++) {
22-
const userData = createUser()
22+
const userData = generateUserInfo()
2323
const user = await prisma.user.create({
2424
select: { id: true },
2525
data: {

exercises/02.authentication/02.solution.2fa/tests/db-utils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { type generateTOTP } from '@epic-web/totp'
22
import { faker } from '@faker-js/faker'
33
import bcrypt from 'bcryptjs'
44
import { UniqueEnforcer } from 'enforce-unique'
5-
import { twoFAVerifyVerificationType } from '#app/routes/settings+/profile.two-factor.verify.tsx'
65
import { getPasswordHash } from '#app/utils/auth.server.ts'
76
import { prisma } from '#app/utils/db.server.ts'
87

@@ -59,10 +58,11 @@ export async function createVerification(input: {
5958
totp: Awaited<ReturnType<typeof generateTOTP>>
6059
userId: string
6160
}) {
61+
const { otp, ...totp } = input.totp
6262
const verification = await prisma.verification.create({
6363
data: {
64-
...input.totp,
65-
type: twoFAVerifyVerificationType,
64+
...totp,
65+
type: '2fa-verify',
6666
target: input.userId,
6767
},
6868
})

exercises/02.authentication/02.solution.2fa/tests/e2e/authentication-2fa.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { generateTOTP } from '@epic-web/totp'
22
import { createUser, createVerification } from '#tests/db-utils.ts'
33
import { test, expect } from '#tests/test-extend.ts'
44

5-
test('authenticates using two-factor authentication (setup)', async ({
5+
test('authenticates using two-factor authentication', async ({
66
navigate,
77
page,
88
}) => {

exercises/02.authentication/02.solution.2fa/tests/test-extend.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ import {
55
type AuthenticateFunction,
66
} from 'playwright-persona'
77
import { href, type Register } from 'react-router'
8+
import { getPasswordHash } from '#app/utils/auth.server.ts'
89
import { prisma } from '#app/utils/db.server.ts'
9-
import { createUser } from '#tests/db-utils'
10+
import { generateUserInfo } from '#tests/db-utils'
1011

1112
interface Fixtures {
1213
navigate: <T extends keyof Register['pages']>(
@@ -17,11 +18,17 @@ interface Fixtures {
1718

1819
const user = definePersona('user', {
1920
async createSession({ page }) {
20-
const user = await createUser()
21+
const user = await prisma.user.create({
22+
data: {
23+
...generateUserInfo(),
24+
roles: { connect: { name: 'user' } },
25+
password: { create: { hash: await getPasswordHash('supersecret') } },
26+
},
27+
})
2128

2229
await page.goto('/login')
2330
await page.getByLabel('Username').fill(user.username)
24-
await page.getByLabel('Password').fill(user.password)
31+
await page.getByLabel('Password').fill('supersecret')
2532
await page.getByRole('button', { name: 'Log in' }).click()
2633
await page.getByText(user.name!).waitFor({ state: 'visible' })
2734

0 commit comments

Comments
 (0)