Files
payloadcms/test/server-functions/components/loginFunction.tsx
James Mikrut 26d709dda6 feat: auth sessions (#12483)
Adds full session functionality into Payload's existing local
authentication strategy.

It's enabled by default, because this is a more secure pattern that we
should enforce. However, we have provided an opt-out pattern for those
that want to stick to stateless JWT authentication by passing
`collectionConfig.auth.useSessions: false`.

Todo:

- [x] @jessrynkar to update the Next.js server functions for refresh and
logout to support these new features
- [x] @jessrynkar resolve build errors

---------

Co-authored-by: Elliot DeNolf <denolfe@gmail.com>
Co-authored-by: Jessica Chowdhury <jessica@trbl.design>
Co-authored-by: Jarrod Flesch <30633324+JarrodMFlesch@users.noreply.github.com>
Co-authored-by: Sasha <64744993+r1tsuu@users.noreply.github.com>
2025-06-27 09:13:52 -04:00

23 lines
463 B
TypeScript

'use server'
import { login } from '@payloadcms/next/auth'
import config from '../config.js'
type LoginArgs = {
email: string
password: string
}
export async function loginFunction({ email, password }: LoginArgs) {
try {
const result = await login({
collection: 'users',
config,
email,
password,
})
} catch (error) {
throw new Error(`Login failed: ${error instanceof Error ? error.message : 'Unknown error'}`)
}
}