Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2024
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. const axios = require('axios');
  2. const { pteroAppAPIKey, pterodactylAPIUrl } = require('../config.json');
  3.  
  4. module.exports = async function getUserIDFromEmail(email) {
  5. try {
  6. const pterodactylAPI = axios.create({
  7. baseURL: pterodactylAPIUrl,
  8. headers: {
  9. 'Authorization': `Bearer ${pteroAppAPIKey}`,
  10. 'Content-Type': 'application/json'
  11. }
  12. });
  13.  
  14. let page = 1;
  15. let users = [];
  16. let hasNextPage = true;
  17.  
  18. while (hasNextPage) {
  19. const usersResponse = await pterodactylAPI.get(`api/application/users?page=${page}`);
  20. console.log(`Page ${page} response:`, usersResponse.data);
  21.  
  22. users = users.concat(usersResponse.data.data);
  23. hasNextPage = usersResponse.data.meta.pagination.current_page < usersResponse.data.meta.pagination.total_pages;
  24. page++;
  25. }
  26.  
  27. for (const user of users) {
  28. if (user.attributes.email === email) {
  29. return user.attributes.id;
  30. }
  31. }
  32.  
  33. throw new Error(`User not found with email ${email}`);
  34. } catch (error) {
  35. console.error(error);
  36. throw error;
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement