# Conditional logic based on logged in user or embedded?

**URL:** <https://talk.observablehq.com/t/conditional-logic-based-on-logged-in-user-or-embedded/4644>\
**Category:** Uncategorized\
**Created:** [February 15, 2021, 2:05pm UTC](https://talk.observablehq.com/t/conditional-logic-based-on-logged-in-user-or-embedded/4644 "2021-02-15T14:05:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nachocab](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/nachocab/32/2426_2.png) [@nachocab](https://talk.observablehq.com/u/nachocab)\
**Post date:** [February 15, 2021, 2:05pm UTC](https://talk.observablehq.com/t/conditional-logic-based-on-logged-in-user-or-embedded/4644/1 "2021-02-15T14:05:39Z")

</div>

Is there a variable that I could access from a notebook that tells me any of these?:

- current logged in user info
- notebook is currently embedded

I’d like to apply some conditional logic based on whether the notebook is embedded on a public website or accessed directly by me in [observablehq.com](http://observablehq.com) but I don’t know if it’s possible

---

<div class="post-metadata">

**Author:** ![mcmcclur](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/mcmcclur/32/2364_2.png) [@mcmcclur](https://talk.observablehq.com/u/mcmcclur)\
**Post date:** [February 15, 2021, 3:42pm UTC](https://talk.observablehq.com/t/conditional-logic-based-on-logged-in-user-or-embedded/4644/2 "2021-02-15T15:42:55Z")

</div>

I don’t know the answers to your questions but I can suggest an approach that might get you roughly what you want. The idea is to use a query string, as suggested in [this description of Parameterized Notebooks](https://observablehq.com/@mbostock/parameterized-notebooks).

For example, here’s a link to one of my webpages:  
[https://marksmath.org/temp/parameterized\_greeting\_iframe.html](https://marksmath.org/temp/parameterized_greeting_iframe.html)

If you follow that link, you should see something like  
“Hello WWW!”

Note that I created that webpage by embedding this notebook:

https://observablehq.com/embed/@mcmcclur/parameterized-greeting?cells=greeting

You’ll notice the difference in who’s greeted. The key is that the code for embedding the `iframe` looks like so:

```
<iframe width="100%" height="109" frameborder="0" src="https://observablehq.com/embed/@mcmcclur/parameterized-greeting?cells=greeting&locale=web"></iframe>

```

Note that I’ve included `locale=web` as part of the query string. If you look at [the notebook](https://observablehq.com/@mcmcclur/parameterized-greeting), you’ll notice that I’m adjusting the greeting based on the value of that parameter.

You can also embed using the Javascript Runtime:  
[https://marksmath.org/temp/parameterized\_greeting.html?locale=web](https://marksmath.org/temp/parameterized_greeting.html?locale=web)  
Then, _assuming users get to your page from a link that you control_, you can alter the appearance based on that query string. Of course, users might fiddle with the query string, though.

---

<div class="post-metadata">

**Author:** ![tomlarkworthy](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/tomlarkworthy/32/5940_2.png) [@tomlarkworthy](https://talk.observablehq.com/u/tomlarkworthy)\
**Post date:** [February 15, 2021, 9:31pm UTC](https://talk.observablehq.com/t/conditional-logic-based-on-logged-in-user-or-embedded/4644/3 "2021-02-15T21:31:59Z")

</div>

The top level URL `html`<a href>`.href` can signal where the notebook is at the top level.

For getting the current user I don’t think there is a way. I did a huge workaround for federated login. You can somewhat track yourself with a cross\* domain cookie, which is the trick for federated login (doesn’t work with safari).

- probably not even a cross domain cookie as embedded notebooks usually have same origin.
