Skip to content

Commit 4458f74

Browse files
authored
ci: template errors not being caught due. fix: error due to updated generated-types User type (#12973)
This PR consists of two separate changes. One change cannot pass CI without the other, so both are included in this single PR. ## CI - ensure types are generated Our website template is currently failing to build due to a type error. This error was introduced by a change in our generated types. Our CI did not catch this issue because it wasn't generating types / import map before attempting to build the templates. This PR updates the CI to generate types first. It also updates some CI step names for improved clarity. ## Fix: type error ![Screenshot 2025-06-29 at 12 53 49@2x](https://github.com/user-attachments/assets/962f1513-bc6c-4e12-9b74-9b891c49900b) This fixes the type error by ensuring we consistently use the _same_ generated `TypedUser` object within payload, instead of `BaseUser`. Previously, we sometimes used the generated-types user and sometimes the base user, which was causing type conflicts depending on what the generated user type was. It also deprecates the `User` type (which was essentially just `BaseUser`), as consumers should use `TypedUser` instead. `TypedUser` will automatically fall back to `BaseUser` if no generated types exists, but will accept passing it a generated-types User. Without this change, additional properties added to the user via generated-types may cause the user object to not be accepted by functions that only accept a `User` instead of a `TypedUser`, which is what failed here. ## Templates: re-generate templates to update generated types --- - To see the specific tasks where the Asana app for GitHub is being used, see below: - https://app.asana.com/0/0/1210668927737258
1 parent cfc7adc commit 4458f74

File tree

53 files changed

+710
-146
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+710
-146
lines changed

.github/workflows/main.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: build
1+
name: ci
22

33
on:
44
pull_request:
@@ -528,7 +528,9 @@ jobs:
528528
# Build listed templates with packed local packages and then runs their int and e2e tests
529529
build-and-test-templates:
530530
runs-on: ubuntu-24.04
531-
needs: build
531+
needs: [changes, build]
532+
if: ${{ needs.changes.outputs.needs_build == 'true' }}
533+
name: build-template-${{ matrix.template }}-${{ matrix.database }}
532534
strategy:
533535
fail-fast: false
534536
matrix:
@@ -558,8 +560,6 @@ jobs:
558560
# - template: with-vercel-website
559561
# database: postgres
560562

561-
name: ${{ matrix.template }}-${{ matrix.database }}
562-
563563
env:
564564
POSTGRES_USER: postgres
565565
POSTGRES_PASSWORD: postgres

packages/next/src/utilities/initPage/handleAuthRedirect.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { User } from 'payload'
1+
import type { TypedUser } from 'payload'
22

33
import { formatAdminURL } from 'payload/shared'
44
import * as qs from 'qs-esm'
@@ -7,7 +7,7 @@ type Args = {
77
config
88
route: string
99
searchParams: { [key: string]: string | string[] }
10-
user?: User
10+
user?: TypedUser
1111
}
1212

1313
export const handleAuthRedirect = ({ config, route, searchParams, user }: Args): string => {

packages/next/src/utilities/initReq.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import type {
66
PayloadRequest,
77
SanitizedConfig,
88
SanitizedPermissions,
9-
User,
9+
TypedUser,
1010
} from 'payload'
1111

1212
import { initI18n } from '@payloadcms/translations'
@@ -37,7 +37,7 @@ type PartialResult = {
3737
languageCode: AcceptedLanguages
3838
payload: Payload
3939
responseHeaders: Headers
40-
user: null | User
40+
user: null | TypedUser
4141
}
4242

4343
// Create cache instances for different parts of our application

packages/next/src/views/Account/ResetPreferences/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
'use client'
2-
import type { User } from 'payload'
2+
import type { TypedUser } from 'payload'
33

44
import { Button, ConfirmationModal, toast, useModal, useTranslation } from '@payloadcms/ui'
55
import * as qs from 'qs-esm'
@@ -9,7 +9,7 @@ const confirmResetModalSlug = 'confirm-reset-modal'
99

1010
export const ResetPreferences: React.FC<{
1111
readonly apiRoute: string
12-
readonly user?: User
12+
readonly user?: TypedUser
1313
}> = ({ apiRoute, user }) => {
1414
const { openModal } = useModal()
1515
const { t } = useTranslation()

packages/next/src/views/Account/Settings/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { I18n } from '@payloadcms/translations'
2-
import type { BasePayload, Config, LanguageOptions, User } from 'payload'
2+
import type { BasePayload, Config, LanguageOptions, TypedUser } from 'payload'
33

44
import { FieldLabel } from '@payloadcms/ui'
55
import React from 'react'
@@ -17,7 +17,7 @@ export const Settings: React.FC<{
1717
readonly languageOptions: LanguageOptions
1818
readonly payload: BasePayload
1919
readonly theme: Config['admin']['theme']
20-
readonly user?: User
20+
readonly user?: TypedUser
2121
}> = (props) => {
2222
const { className, i18n, languageOptions, payload, theme, user } = props
2323

packages/next/src/views/Version/fetchVersions.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import {
44
type PayloadRequest,
55
type SelectType,
66
type Sort,
7+
type TypedUser,
78
type TypeWithVersion,
8-
type User,
99
type Where,
1010
} from 'payload'
1111

@@ -28,7 +28,7 @@ export const fetchVersion = async <TVersionData extends object = object>({
2828
overrideAccess?: boolean
2929
req: PayloadRequest
3030
select?: SelectType
31-
user?: User
31+
user?: TypedUser
3232
}): Promise<null | TypeWithVersion<TVersionData>> => {
3333
try {
3434
if (collectionSlug) {
@@ -88,7 +88,7 @@ export const fetchVersions = async <TVersionData extends object = object>({
8888
req: PayloadRequest
8989
select?: SelectType
9090
sort?: Sort
91-
user?: User
91+
user?: TypedUser
9292
where?: Where
9393
}): Promise<null | PaginatedDocs<TypeWithVersion<TVersionData>>> => {
9494
const where: Where = { and: [...(whereFromArgs ? [whereFromArgs] : [])] }
@@ -160,7 +160,7 @@ export const fetchLatestVersion = async <TVersionData extends object = object>({
160160
req: PayloadRequest
161161
select?: SelectType
162162
status: 'draft' | 'published'
163-
user?: User
163+
user?: TypedUser
164164
where?: Where
165165
}): Promise<null | TypeWithVersion<TVersionData>> => {
166166
const and: Where[] = [

packages/next/src/views/Versions/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type {
44
SanitizedCollectionConfig,
55
SanitizedConfig,
66
SanitizedGlobalConfig,
7-
User,
7+
TypedUser,
88
} from 'payload'
99

1010
export type DefaultVersionsViewProps = {
@@ -18,6 +18,6 @@ export type DefaultVersionsViewProps = {
1818
i18n: I18n
1919
id: number | string
2020
limit: number
21-
user: User
21+
user: TypedUser
2222
versionsData: PaginatedDocs<Document>
2323
}

packages/payload/src/admin/forms/Field.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import type { I18nClient } from '@payloadcms/translations'
22
import type { MarkOptional } from 'ts-essentials'
33

4-
import type { SanitizedFieldPermissions, User } from '../../auth/types.js'
4+
import type { SanitizedFieldPermissions } from '../../auth/types.js'
55
import type { ClientBlock, ClientField, Field } from '../../fields/config/types.js'
6+
import type { TypedUser } from '../../index.js'
67
import type { DocumentPreferences } from '../../preferences/types.js'
78
import type { Operation, Payload, PayloadRequest } from '../../types/index.js'
89
import type {
@@ -90,7 +91,7 @@ export type ServerComponentProps = {
9091
preferences: DocumentPreferences
9192
req: PayloadRequest
9293
siblingData: Data
93-
user: User
94+
user: TypedUser
9495
value?: unknown
9596
}
9697

packages/payload/src/auth/operations/login.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ import type {
55
Collection,
66
DataFromCollectionSlug,
77
} from '../../collections/config/types.js'
8-
import type { CollectionSlug } from '../../index.js'
8+
import type { CollectionSlug, TypedUser } from '../../index.js'
99
import type { PayloadRequest, Where } from '../../types/index.js'
10-
import type { User } from '../types.js'
1110

1211
import { buildAfterOperation } from '../../collections/operations/utils.js'
1312
import {
@@ -32,7 +31,7 @@ import { resetLoginAttempts } from '../strategies/local/resetLoginAttempts.js'
3231
export type Result = {
3332
exp?: number
3433
token?: string
35-
user?: User
34+
user?: TypedUser
3635
}
3736

3837
export type Arguments<TSlug extends CollectionSlug> = {

packages/payload/src/auth/operations/me.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { decodeJwt } from 'jose'
22

33
import type { Collection } from '../../collections/config/types.js'
4+
import type { TypedUser } from '../../index.js'
45
import type { PayloadRequest } from '../../types/index.js'
5-
import type { ClientUser, User } from '../types.js'
6+
import type { ClientUser } from '../types.js'
67

78
export type MeOperationResult = {
89
collection?: string
@@ -42,7 +43,7 @@ export const meOperation = async (args: Arguments): Promise<MeOperationResult> =
4243
overrideAccess: false,
4344
req,
4445
showHiddenFields: false,
45-
})) as User
46+
})) as TypedUser
4647

4748
if (user) {
4849
user.collection = collection.config.slug

0 commit comments

Comments
 (0)