Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/gau/src/solidstart/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { CreateAuthOptions, RefreshSessionOptions } from '../core'
import type { AuthInstance } from '../core/serverSession'
import type { OAuthProvider } from '../oauth'
import process from 'node:process'
import { DEV } from 'esm-env'
import { createHandler, REFRESHED_TOKEN_HEADER } from '../core'
import { createRequestSessionCache, resolveAuth, resolveServerSession } from '../core/serverSession'

Expand All @@ -22,7 +22,7 @@ export { REFRESHED_TOKEN_HEADER }
export function SolidAuth<const TProviders extends OAuthProvider<any>[]>(optionsOrAuth: CreateAuthOptions<TProviders> | AuthInstance<TProviders>) {
const auth = resolveAuth(optionsOrAuth)

auth.development = process.env.NODE_ENV === 'development'
auth.development = DEV

if (!auth.errorRedirect)
auth.errorRedirect = '/auth/error'
Expand Down
30 changes: 16 additions & 14 deletions packages/gau/test/solidstart/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { readFile } from 'node:fs/promises'
import { DEV } from 'esm-env'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { NULL_SESSION, REFRESHED_TOKEN_HEADER, SESSION_COOKIE_NAME } from '../../src/core'
import { authMiddleware, createSolidStartGetServerSession, refreshMiddleware, SolidAuth } from '../../src/solidstart/index'
Expand Down Expand Up @@ -29,6 +31,7 @@ describe('solidAuth', () => {
beforeEach(() => {
mockAuth.providerMap = new Map()
mockAuth.validateSession.mockReset()
delete mockAuth.development
})

it('should return GET, POST, and OPTIONS handlers', () => {
Expand Down Expand Up @@ -57,20 +60,19 @@ describe('solidAuth', () => {
expect(GET).toBeInstanceOf(Function)
})

it('sets development based on NODE_ENV', () => {
const original = process.env.NODE_ENV
try {
process.env.NODE_ENV = 'development'
SolidAuth({ providers: [], adapter: {} as any } as any)
expect(mockAuth.development).toBe(true)

process.env.NODE_ENV = 'production'
SolidAuth({ providers: [], adapter: {} as any } as any)
expect(mockAuth.development).toBe(false)
}
finally {
process.env.NODE_ENV = original
}
it('sets development from esm-env', () => {
SolidAuth({ providers: [], adapter: {} as any } as any)

expect(mockAuth.development).toBe(DEV)
})

it('does not statically import process in the SolidStart runtime source', async () => {
const source = await readFile(new URL('../../src/solidstart/index.ts', import.meta.url), 'utf8')
const imports = source.match(/^import\s+.*$/gm)?.join('\n') ?? ''

expect(imports).not.toMatch(/\bprocess\b/)
expect(source).not.toContain('node:process')
expect(source).not.toMatch(/\bprocess\.env\b/)
})
})

Expand Down
Loading