login.js 875 B

123456789101112131415161718192021222324252627282930
  1. const { r2rClient } = require("r2r-js");
  2. const client = new r2rClient("https://r2rserver.cocorobo.cn/");
  3. module.exports = async function handler(req, res) {
  4. console.log("Received a request at /api/login");
  5. if (req.method === "POST") {
  6. // const { query } = req.body;
  7. try {
  8. // Login with each request. In a production app, you'd want to manage sessions.
  9. const response = await client.users.login({
  10. email:"xujiawei@cocorobo.cc",
  11. password:"usestudio-1"
  12. })
  13. console.log(response);
  14. res.status(200).json({
  15. result: response.results,
  16. });
  17. } catch (error) {
  18. res.status(500).json({
  19. error: error instanceof Error ? error.message : "An error occurred",
  20. });
  21. }
  22. } else {
  23. res.setHeader("Allow", ["POST"]);
  24. res.status(405).end(`Method ${req.method} Not Allowed`);
  25. }
  26. };