Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable protection on the script to honour not logged in status for accounts!? #36

Open
corkiejp opened this issue Jan 13, 2025 · 6 comments

Comments

@corkiejp
Copy link

I was advised by Perplexity AI to use this update script for embeds.

https://cdn.jsdelivr.net/npm/bsky-embed/dist/bsky-embed.es.js

Is it the same updated script as provided here?

I tried to add protection on the page myself, but accounts still display and the setting ignored.

This is my attempt at using edited script:-

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Display Bluesky account!</title>
  <script type="module" src="https://cdn.jsdelivr.net/npm/bsky-embed/dist/bsky-embed.es.js" async></script>
  <script>
    async function setUsername() {
      const urlParams = new URLSearchParams(window.location.search);
      const username = urlParams.get('username');
      if (username) {
        const bskyEmbed = document.querySelector('bsky-embed');
        if (bskyEmbed) {
          bskyEmbed.setAttribute('username', username);
          
          // Attempt to fetch user data
          try {
            const response = await fetch(`https://bsky.social/xrpc/app.bsky.actor.getProfile?actor=${username}`);
            const data = await response.json();
            if (!data || !data.did) {
              throw new Error('No data available');
            }
          } catch (error) {
            console.error('Failed to fetch user data:', error);
            bskyEmbed.innerHTML = '<p>This account may be private or not accessible.</p>';
          }
        }
      }
    }

    document.addEventListener('DOMContentLoaded', setUsername);
  </script>
<base target="_parent">  
</head>

<body>
  <bsky-embed
    mode=""
    limit="15"
    link-image="true"
    link-target="_blank"
    load-more="true"
    date-format="numeric"
  ></bsky-embed>
</body>
</html>
@corkiejp
Copy link
Author

Just noticed it is the same script, I had download the .js file to put on my host.

My code also available here:- https://github.com/corkiejp/corkiejp.github.io/blob/c4b5b78e5368fe5e01776651f1bdad5c7c960cad/blueskyacc_p.html

@Vincenius
Copy link
Owner

Hey the bsky-embed web component just handles rendering a public feed. If you want to dynamically set the username you need to add it to load the script without "async" and add the HTML dynamically like this:

const bskyEmbed = document.createElement('bsky-embed');
bskyEmbed.setAttribute('username', username);
// ... set other properties
document.body.appendChild(bskyEmbed);

For more advanced use cases like the profile stuff you have in your code, you need to take a look on the official bsky api

@corkiejp
Copy link
Author

Thanks for the reply, code as I have it actually works.
corkiejp.bsky.social

But I was attempting to try and honour this setting:-
loggedout

But just complicated the script in attempt to do so.

@Vincenius
Copy link
Owner

Ah okay, I'll take a look if I can update the code

@corkiejp
Copy link
Author

I found another script with the same issue. They have suggested that it may require a change to the api itself by Bluesky!

https://bsky.app/profile/heion.net/post/3lfqphlrc322l

@corkiejp
Copy link
Author

Image

The above is how https://embed.bsky.app/static/embed.js handles the result.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants