import wixUsersBackend from 'wix-users-backend'; import {fetch} from 'wix-fetch'; const CLIENT_ID = '1112811133259218974'; const CLIENT_SECRET = 'MorYUCBU0MLMKdAnkggpOxon-GaXSbLG'; const REDIRECT_URI = 'https://www.stockmarketchat.net/_api/wix-public/myapp/auth/callback'; // Handles the authentication callback export function myApp_auth_callback(request) { const code = request.query.code; const tokenEndpoint = `https://discord.com/api/oauth2/token`; const payload = { grant_type: 'authorization_code', code, redirect_uri: REDIRECT_URI }; const options = { method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded', 'Authorization': `Basic ${Buffer.from(`${CLIENT_ID}:${CLIENT_SECRET}`).toString('base64')}` }, body: Object.keys(payload) .map(key => encodeURIComponent(key) + '=' + encodeURIComponent(payload[key])) .join('&') }; return fetch(tokenEndpoint, options) .then(response => response.json()) .then(data => { const accessToken = data.access_token; // Use the access token to authenticate the user and handle the login logic here // e.g., create a session for the authenticated user // wixUsersBackend.createSession() }); }
top of page
bottom of page