-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moves drupal sdk to centralized util and adds redirect if not logged in
- Loading branch information
Showing
6 changed files
with
67 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"name": "vue2", | ||
"name": "vue2-example", | ||
"version": "0.1.0", | ||
"private": true, | ||
"scripts": { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,12 @@ | ||
import VueRouter from 'vue-router'; | ||
|
||
declare module '*.vue' { | ||
import Vue from 'vue'; | ||
export default Vue; | ||
} | ||
|
||
declare module 'vue/types/vue' { | ||
interface Vue { | ||
$router: VueRouter; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { Drupal, DrupalAuth } from 'drupal-js-sdk'; | ||
|
||
const drupal = new Drupal().initialize({ | ||
baseURL: process.env.VUE_APP_BASE_URL || '' | ||
}); | ||
|
||
export default new DrupalAuth(drupal); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,49 @@ | ||
<template> | ||
<div class="home"> | ||
<nav> | ||
<router-link to="/login">Login</router-link> | ||
<button v-if="user.loggedIn" @click="logout">Log out</button> | ||
<router-link v-else to="/login">Login</router-link> | ||
</nav> | ||
<p> | ||
You are logged in as {{ user.name }} | ||
</p> | ||
</div> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import Vue from 'vue'; | ||
import drupal from '../utils/drupal-sdk'; | ||
export default Vue.extend({ | ||
name: 'Home' | ||
name: 'Home', | ||
data() { | ||
return { | ||
user: { | ||
name: '', | ||
loggedIn: false | ||
} | ||
}; | ||
}, | ||
methods: { | ||
async checkAuthStatus() { | ||
const status = drupal.loginStatus(); | ||
this.user.loggedIn = Boolean(status); | ||
this.user.name = localStorage.getItem('username') || ''; | ||
}, | ||
logout() { | ||
drupal.logout().then(() => { | ||
this.user.loggedIn = false; | ||
localStorage.removeItem('username'); | ||
this.$router.push('/login'); | ||
}); | ||
} | ||
}, | ||
async mounted() { | ||
console.log(drupal); | ||
await this.checkAuthStatus(); | ||
if (!this.user.loggedIn) { | ||
this.$router.push('/login'); | ||
} | ||
} | ||
}); | ||
</script> |