[PR #4695] [MERGED] fix: device authorization plugin #5535

Closed
opened 2026-03-13 12:26:20 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/4695
Author: @bytaesu
Created: 9/16/2025
Status: Merged
Merged: 9/16/2025
Merged by: @himself65

Base: canaryHead: fix/device-authorization-plugin


📝 Commits (2)

  • 1d0b346 fix: set session context and store session in secondary storage after device approval
  • e2348ea docs: update docs to match client structure

📊 Changes

2 files changed (+28 additions, -6 deletions)

View changed files

📝 docs/content/docs/plugins/device-authorization.mdx (+6 -6)
📝 packages/better-auth/src/plugins/device-authorization/index.ts (+22 -0)

📄 Description

Summary

This PR fixes a bug in the session handling logic of the Device Authorization plugin and updates the documentation to match the actual client specifications.

This bug occurs because the plugin runs in a cookieless environment, so setSessionCookie is not called, causing its internal logic to be skipped.

Problem

  • Session setup logic in the context was missing.
  • When using secondary_storage, sessions were not saved, making login impossible.

Future Consideration

The current verification_uri points to the /device endpoint, which is not the page users actually use for authentication.

Ideally, a default HTML page could be provided (like an error page) with an option like verificationPageUrl for customization. This would be a breaking change, so it’s not included in this PR.

I already have a personal implementation for this. I can include it if the Better Auth team wants.


Summary by cubic

Fixes session handling in the Device Authorization plugin so approved devices create and persist sessions in cookieless setups and with secondary storage. Updates docs to match the actual client API (device(), device.approve(), device.deny()).

  • Bug Fixes
    • Set new session context after device approval so hooks/plugins receive it.
    • Store sessions in secondary storage when enabled, using the session token TTL.
    • Updated docs and examples to use authClient.device(), device.approve(), and device.deny().

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/better-auth/better-auth/pull/4695 **Author:** [@bytaesu](https://github.com/bytaesu) **Created:** 9/16/2025 **Status:** ✅ Merged **Merged:** 9/16/2025 **Merged by:** [@himself65](https://github.com/himself65) **Base:** `canary` ← **Head:** `fix/device-authorization-plugin` --- ### 📝 Commits (2) - [`1d0b346`](https://github.com/better-auth/better-auth/commit/1d0b346f16d16e954e58f17076577e9f29ea6cd9) fix: set session context and store session in secondary storage after device approval - [`e2348ea`](https://github.com/better-auth/better-auth/commit/e2348ea8acb48b07153226d777455bb5d2975df9) docs: update docs to match client structure ### 📊 Changes **2 files changed** (+28 additions, -6 deletions) <details> <summary>View changed files</summary> 📝 `docs/content/docs/plugins/device-authorization.mdx` (+6 -6) 📝 `packages/better-auth/src/plugins/device-authorization/index.ts` (+22 -0) </details> ### 📄 Description ## Summary This PR fixes a bug in the session handling logic of the Device Authorization plugin and updates the documentation to match the actual client specifications. This bug occurs because the plugin runs in a cookieless environment, so setSessionCookie is not called, causing its internal logic to be skipped. ## Problem - Session setup logic in the context was missing. - When using secondary_storage, sessions were not saved, making login impossible. ## Future Consideration The current verification_uri points to the /device endpoint, which is not the page users actually use for authentication. Ideally, a default HTML page could be provided (like an error page) with an option like verificationPageUrl for customization. This would be a breaking change, so it’s not included in this PR. I already have a personal implementation for this. I can include it if the Better Auth team wants. <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Fixes session handling in the Device Authorization plugin so approved devices create and persist sessions in cookieless setups and with secondary storage. Updates docs to match the actual client API (device(), device.approve(), device.deny()). - **Bug Fixes** - Set new session context after device approval so hooks/plugins receive it. - Store sessions in secondary storage when enabled, using the session token TTL. - Updated docs and examples to use authClient.device(), device.approve(), and device.deny(). <!-- End of auto-generated description by cubic. --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-03-13 12:26:20 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#5535