本页还没有译文
本页 4 段还没译成简体中文,下面显示的是英文原文。Handling Authentication
还没翻译译自英文(ai-sdk.dev)本页 4 段都还没译
Warning
AI SDK RSC is currently experimental. We recommend using AI SDK UI for production. For guidance on migrating from RSC to UI, see our migration guide.
The RSC API makes extensive use of Server Actions to power streaming values and UI from the server.
Server Actions are exposed as public, unprotected endpoints. As a result, you should treat Server Actions as you would public-facing API endpoints and ensure that the user is authorized to perform the action before returning any data.
'use server';
import { cookies } from 'next/headers';
import { createStreamableUI } from '@ai-sdk/rsc';
import { validateToken } from '../utils/auth';
export const getWeather = async () => {
const token = cookies().get('token');
if (!token || !validateToken(token)) {
return {
error: 'This action requires authentication',
};
}
const streamableDisplay = createStreamableUI(null);
streamableDisplay.update(<Skeleton />);
streamableDisplay.done(<Weather />);
return {
display: streamableDisplay.value,
};
};AI 翻译查看英文原文