<template>
  <div v-if="loaded">
    <slot v-if="isAuthenticated"></slot>
    <p v-else>
      Please
      <router-link to="/login">log in</router-link>
      first
    </p>
  </div>
</template>

<script>
import { getJson } from '@/util/fetch';

export default {
  data() {
    return {
      isAuthenticated: undefined,
      loaded: false
    }
  },
  created() {
    getJson('/authenticated').then(json => {
      this.loaded = true;
      this.isAuthenticated = json.isAuthenticated;
    });
  }
}
</script>
