docs: minor formatting tweaks to server function examples (#12102)

Misc formatting tweaks for server function examples in docs.
This commit is contained in:
Jessica Chowdhury
2025-04-14 13:05:16 +01:00
committed by GitHub
parent 6b349378e0
commit c661d33b13

View File

@@ -312,7 +312,7 @@ export const PostForm: React.FC = () => {
Managing authentication with the Local API can be tricky as you have to handle cookies and tokens yourself, and there aren't built-in logout or refresh functions since these only modify cookies. To make this easier, we provide `login`, `logout`, and `refresh` as ready-to-use server functions. They take care of the underlying complexity so you don't have to. Managing authentication with the Local API can be tricky as you have to handle cookies and tokens yourself, and there aren't built-in logout or refresh functions since these only modify cookies. To make this easier, we provide `login`, `logout`, and `refresh` as ready-to-use server functions. They take care of the underlying complexity so you don't have to.
### `login` ### Login
Logs in a user by verifying credentials and setting the authentication cookie. This function allows login via username or email, depending on the collection auth configuration. Logs in a user by verifying credentials and setting the authentication cookie. This function allows login via username or email, depending on the collection auth configuration.
@@ -357,6 +357,7 @@ export async function loginAction({
```tsx ```tsx
'use client' 'use client'
import { useState } from 'react' import { useState } from 'react'
import { loginAction } from '../loginAction' import { loginAction } from '../loginAction'
@@ -390,7 +391,7 @@ export default function LoginForm() {
} }
``` ```
### `logout` ### Logout
Logs out the current user by clearing the authentication cookie. Logs out the current user by clearing the authentication cookie.
@@ -423,6 +424,7 @@ export async function logoutAction() {
```tsx ```tsx
'use client' 'use client'
import { logoutAction } from '../logoutAction' import { logoutAction } from '../logoutAction'
export default function LogoutButton() { export default function LogoutButton() {
@@ -430,7 +432,7 @@ export default function LogoutButton() {
} }
``` ```
### `refresh` ### Refresh
Refreshes the authentication token for the logged-in user. Refreshes the authentication token for the logged-in user.
@@ -451,7 +453,7 @@ import config from '@payload-config'
export async function refreshAction() { export async function refreshAction() {
try { try {
return await refresh({ return await refresh({
collection: 'users', // update this to your collection slug collection: 'users', // pass your collection slug
config, config,
}) })
} catch (error) { } catch (error) {
@@ -466,6 +468,7 @@ export async function refreshAction() {
```tsx ```tsx
'use client' 'use client'
import { refreshAction } from '../actions/refreshAction' import { refreshAction } from '../actions/refreshAction'
export default function RefreshTokenButton() { export default function RefreshTokenButton() {