TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Session storage should be preferable to JWT auth all things remaining same

2 点作者 pyeri大约 2 个月前
There are usually two ways of authenticating an incoming request for accessing an API resource.<p>1. The authentication key or password can be passed through a JSON field or authorization header. This can be compared to the key already stored in session storage. The simplest approach is `authorizationKey == session(&#x27;key&#x27;)`. This requires you to have session storage feature on the backend.<p>2. The JWT approach relieves you from session storage but then it needs to compute the signature verification (HMAC&#x2F;RSA&#x2F;ECDSA) for each incoming API request.<p>Thus, the first approach requires you to have session storage, and the second approach doesn&#x27;t need session storage but at the cost of extra computing overhead for performing cryptographic calculations.<p>Considering that RAM is usually cheaper than processing power, it makes far more economic sense to use the former approach everywhere for authentication than the latter. Especially as you start scaling the app to millions of requests, that&#x27;s when the VPS hosting bill amount starts rising and the approach will need optimization.

1 comment

NoahZuniga大约 2 个月前
Most of the value from JWTs is from not having to access storage to verify authentication. If you have billions of sessions, it isn&#x27;t easy to just have one server respond to millions of requests per second. Also it&#x27;s easier to share authentication information between companies using JWTs. IE: cloudflare access includes a JWT token with forwarded requests.