PageSourceSearch

https://www.playboy.com/wp-content/themes/playboy/js/auth-google.js?ver=1790171547

js playboy.com collected 2026-09-24 08:53:28 UTC 3,828 bytes, 107 lines download raw bytes

1/**
2 * Google Sign-In button for /login/ and /join/.
3 *
4 * Loads Google Identity Services (gsi/client), renders the button into the
5 * #pb-google-signin container if present, and POSTs the returned credential
6 * JWT to /wp-json/playboy/v1/identity/google. The endpoint verifies the JWT
7 * server-side, finds/creates the WP user, and returns a redirect URL.
8 *
9 * Configuration arrives via wp_localize_script as window.pbGoogleAuth:
10 *   { clientId, intent: 'login'|'join', planId, redirectTo, restUrl, restNonce }
11 */
12(function () {
13    'use strict';
14
15    var config = window.pbGoogleAuth || {};
16    if (!config.clientId || !config.restUrl) {
17        return;
18    }
19
20    var container = document.getElementById('pb-google-signin');
21    if (!container) {
22        return;
23    }
24
25    function init() {
26        if (!window.google || !window.google.accounts || !window.google.accounts.id) {
27            // GIS hasn't loaded yet — defer one more tick.
28            setTimeout(init, 50);
29            return;
30        }
31
32        window.google.accounts.id.initialize({
33            client_id:   config.clientId,
34            callback:    handleCredential,
35            ux_mode:     'popup',
36            auto_select: false,
37        });
38
39        window.google.accounts.id.renderButton(container, {
40            theme:           'outline',
41            size:            'large',
42            type:            'standard',
43            text:            config.intent === 'join' ? 'signup_with' : 'signin_with',
44            shape:           'rectangular',
45            logo_alignment:  'left',
46            width:           280,
47        });
48    }
49
50    function handleCredential(response) {
51        if (!response || !response.credential) {
52            showError('Google did not return a sign-in token. Please try again.');
53            return;
54        }
55
56        var body = new FormData();
57        body.append('credential',  response.credential);
58        body.append('intent',      config.intent     || 'login');
59        body.append('plan_id',     config.planId     || 0);
60        body.append('redirect_to', config.redirectTo || '');
61
62        fetch(config.restUrl, {
63            method:      'POST',
64            credentials: 'same-origin',
65            headers:     { 'X-WP-Nonce': config.restNonce || '' },
66            body:        body,
67        })
68        .then(function (r) { return r.json().then(function (data) { return { ok: r.ok, data: data }; }); })
69        .then(function (result) {
70            if (!result.ok || !result.data || !result.data.redirect) {
71                var msg = (result.data && result.data.message) || 'Sign-in failed. Please try again.';
72                showError(msg);
73                return;
74            }
75            window.location.href = result.data.redirect;
76        })
77        .catch(function () {
78            showError('Sign-in failed. Please try again.');
79        });
80    }
81
82    function showError(msg) {
83        // Re-use the existing error element on whichever flow we're in.
84        var el = document.querySelector('.pb-login-error, .pb-join-error');
85        if (el) {
86            el.innerHTML = msg;
87            el.style.display = 'block';
88            return;
89        }
90        // Fallback for unexpected DOM — better noisy than silent.
91        window.alert(msg);
92    }
93
94    // Load Google Identity Services — single global script, idempotent if a
95    // second page on the same SPA navigation already added it.
96    if (!document.querySelector('script[data-pb-gsi]')) {
97        var script = document.createElement('script');
98        script.src   = 'https://accounts.google.com/gsi/client';
99        script.async = true;
100        script.defer = true;
101        script.setAttribute('data-pb-gsi', '1');
102        script.onload = init;
103        document.head.appendChild(script);
104    } else {
105        init();
106    }
107})();

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.