NextAuth和typeorm-在API端点中检索存储库

发布于 2025-01-25 23:37:18 字数 278 浏览 3 评论 0 原文

我有一个 nextjs app, nextAuth typeorm 。 我正在寻找在API端点中检索特定用户或自定义实体的可能性。 但是,我不知道该如何正确执行此操作。 我不想重新调整每个API上的连接选项以进行TypeOmm,并希望使用适配器设置的连接。 (单身人士的想法)。

有人对如何实现这一目标有任何想法吗?

祝您有美好的一天!

I've got an NextJS app with NextAuth and TypeORM.
I'm looking for the possibility to retrieve a specific user or custom entity in an api endpoint.
However, i don't know how to do this properly.
I don't want to re-initialize the connection options on every api for TypeORM and would like to use the connection set by the adapter. (idea of a singleton).

Someone has any idea on how to achieve that ?

Have a nice day !

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

帅气称霸 2025-02-01 23:37:18

我不知道我是否有您的问题,但我认为最好的方法是创建您的实体,通过typeorm与同步 Option option> True 连接。
它将从定义的模型中创建和更新所有表和列。

然后,您可以创建另一个连接以在API路由中使用。
我认为,如果没有自定义实现服务器实现,Vercel可以通过单个连接部署它。

这个家伙做了一个解决方案,您可以尝试

函数的另一种方法

这是同一 “ rel =“ nofollow noreferrer”> https://github.com/typeorm/typeorm/issues/6241#issuecomment-643690383

I don’t know if I got your question, but I think the best way of doing it is by creating your Entities, connecting via TypeORM with synchronize option true.
It will create and update all your tables and columns from your defined model.

Then, you can create another connection to use in your api routes.
I don’t think Vercel can deploy it with a single connection without a custom implementation server implementation.

This guy made a solution that you can try

https://github.com/vercel/next.js/discussions/12254#discussioncomment-19769

This is another approach to the same function

https://github.com/typeorm/typeorm/issues/6241#issuecomment-643690383

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文