Skip to content

Commit 85233ae

Browse files
committed
Fix most test an linting issue
1 parent c82ac31 commit 85233ae

File tree

3 files changed

+14
-28
lines changed

3 files changed

+14
-28
lines changed

app/routes/_auth+/auth.$provider.callback.test.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { invariant } from '@epic-web/invariant'
22
import { faker } from '@faker-js/faker'
3+
import { SetCookie } from '@mjackson/headers'
34
import { http } from 'msw'
45
import { afterEach, expect, test } from 'vitest'
56
import { twoFAVerificationType } from '#app/routes/settings+/profile.two-factor.tsx'
67
import { getSessionExpirationDate, sessionKey } from '#app/utils/auth.server.ts'
7-
import { connectionSessionStorage } from '#app/utils/connections.server.ts'
88
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'
@@ -219,19 +219,25 @@ async function setupRequest({
219219
const state = faker.string.uuid()
220220
url.searchParams.set('state', state)
221221
url.searchParams.set('code', code)
222-
const connectionSession = await connectionSessionStorage.getSession()
223-
connectionSession.set('oauth2:state', state)
224222
const authSession = await authSessionStorage.getSession()
225223
if (sessionId) authSession.set(sessionKey, sessionId)
226224
const setSessionCookieHeader =
227225
await authSessionStorage.commitSession(authSession)
228-
const setConnectionSessionCookieHeader =
229-
await connectionSessionStorage.commitSession(connectionSession)
226+
const searchParams = new URLSearchParams({ code, state })
227+
let authCookie = new SetCookie({
228+
name: 'github',
229+
value: searchParams.toString(),
230+
path: '/',
231+
sameSite: 'Lax',
232+
httpOnly: true,
233+
maxAge: 60 * 10,
234+
secure: process.env.NODE_ENV === 'production' || undefined,
235+
})
230236
const request = new Request(url.toString(), {
231237
method: 'GET',
232238
headers: {
233239
cookie: [
234-
convertSetCookieToCookie(setConnectionSessionCookieHeader),
240+
authCookie.toString(),
235241
convertSetCookieToCookie(setSessionCookieHeader),
236242
].join('; '),
237243
},

app/routes/_auth+/onboarding_.$provider.tsx

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import {
2323
signupWithConnection,
2424
requireAnonymous,
2525
} from '#app/utils/auth.server.ts'
26-
import { connectionSessionStorage } from '#app/utils/connections.server'
2726
import { ProviderNameSchema } from '#app/utils/connections.tsx'
2827
import { prisma } from '#app/utils/db.server.ts'
2928
import { useIsPending } from '#app/utils/misc.tsx'
@@ -78,24 +77,17 @@ async function requireData({
7877

7978
export async function loader({ request, params }: Route.LoaderArgs) {
8079
const { email } = await requireData({ request, params })
81-
const connectionSession = await connectionSessionStorage.getSession(
82-
request.headers.get('cookie'),
83-
)
80+
8481
const verifySession = await verifySessionStorage.getSession(
8582
request.headers.get('cookie'),
8683
)
8784
const prefilledProfile = verifySession.get(prefilledProfileKey)
8885

89-
const formError = connectionSession.get(authenticator.sessionErrorKey)
90-
const hasError = typeof formError === 'string'
91-
9286
return {
9387
email,
9488
status: 'idle',
9589
submission: {
96-
status: hasError ? 'error' : undefined,
9790
initialValue: prefilledProfile ?? {},
98-
error: { '': hasError ? [formError] : [] },
9991
} as SubmissionResult,
10092
}
10193
}

app/utils/connections.server.ts

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,9 @@
1-
import { createCookieSessionStorage } from 'react-router'
1+
// import { createCookieSessionStorage } from 'react-router'
22
import { type ProviderName } from './connections.tsx'
33
import { GitHubProvider } from './providers/github.server.ts'
44
import { type AuthProvider } from './providers/provider.ts'
55
import { type Timings } from './timing.server.ts'
66

7-
export const connectionSessionStorage = createCookieSessionStorage({
8-
cookie: {
9-
name: 'en_connection',
10-
sameSite: 'lax', // CSRF protection is advised if changing to 'none'
11-
path: '/',
12-
httpOnly: true,
13-
maxAge: 60 * 10, // 10 minutes
14-
secrets: process.env.SESSION_SECRET.split(','),
15-
secure: process.env.NODE_ENV === 'production',
16-
},
17-
})
18-
197
export const providers: Record<ProviderName, AuthProvider> = {
208
github: new GitHubProvider(),
219
}

0 commit comments

Comments
 (0)