Skip to content

Conversation

AurimarL
Copy link
Contributor

@AurimarL AurimarL commented Oct 2, 2025

What?

This PR introduces a new logout helper and corresponding SDK method for authentication collections.
It mirrors the existing login helper, allowing developers to easily call the Payload logout endpoint with proper typing.

Why?

Currently, the SDK provides a typed login method but lacks a counterpart for logging out.
By adding this method, SDK users can:

  • Log out from the current session
  • Optionally log out from all sessions (allSessions=true)
  • Rely on fully typed options and results, improving DX

How?

  • Added LogoutOptions and LogoutResult types
  • Implemented logout helper function using sdk.request
  • Extended the SDK class with logout method, mirroring the login method’s pattern

Example usage

const result = await sdk.logout({
  collection: 'users',
  allSessions: false,
})

console.log(result.message)
// -> "You have been logged out"

@AurimarL AurimarL changed the title feat(sdk-auth): add logout helper and SDK method feat(sdk): add logout helper and SDK method Oct 2, 2025
Copy link
Member

@r1tsuu r1tsuu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!
Needs an integration test, there is one already for login

it('should execute login', async () => {
const res = await sdk.login({
collection: 'users',
data: { email: testUserCredentials.email, password: testUserCredentials.password },
})
expect(res.user.email).toBe(testUserCredentials.email)
})

Your test would verify that the session was deleted.

options: LogoutOptions<T, TSlug>,
init?: RequestInit,
): Promise<LogoutResult> {
const url = `/${options.collection}/logout?allSessions=${options.allSessions ?? false}`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the args property of sdk.request instead like in all other operations.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this one is like verifyEmail, no args is used

@AurimarL AurimarL requested a review from r1tsuu October 2, 2025 01:48
@r1tsuu
Copy link
Member

r1tsuu commented Oct 3, 2025

Looks like the new test is failing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants