Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const axios = require('axios');
- const { pteroAppAPIKey, pterodactylAPIUrl } = require('../config.json');
- module.exports = async function getUserIDFromEmail(email) {
- try {
- const pterodactylAPI = axios.create({
- baseURL: pterodactylAPIUrl,
- headers: {
- 'Authorization': `Bearer ${pteroAppAPIKey}`,
- 'Content-Type': 'application/json'
- }
- });
- let page = 1;
- let users = [];
- let hasNextPage = true;
- while (hasNextPage) {
- const usersResponse = await pterodactylAPI.get(`api/application/users?page=${page}`);
- console.log(`Page ${page} response:`, usersResponse.data);
- users = users.concat(usersResponse.data.data);
- hasNextPage = usersResponse.data.meta.pagination.current_page < usersResponse.data.meta.pagination.total_pages;
- page++;
- }
- for (const user of users) {
- if (user.attributes.email === email) {
- return user.attributes.id;
- }
- }
- throw new Error(`User not found with email ${email}`);
- } catch (error) {
- console.error(error);
- throw error;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement