Skip to content
This repository was archived by the owner on Mar 21, 2025. It is now read-only.

Commit bc822df

Browse files
committed
moved out goTrue initialisation logic into helpers dir
1 parent 584b214 commit bc822df

File tree

3 files changed

+31
-14
lines changed

3 files changed

+31
-14
lines changed

src/helpers/init-auth.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import GoTrue from "gotrue-js";
2+
3+
//TODO - detect local host then use parameter from a config or something else
4+
5+
export const Auth = new GoTrue({
6+
APIUrl: "https://simple-vue-netlify-auth.netlify.com/.netlify/identity",
7+
audience: "",
8+
setCookie: false
9+
});
10+
11+
console.log("hello from go true helper", Auth)

src/main.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,17 @@ import store from './store'
55
import restoreState from "./helpers/restore-state"
66
import attemptToAuthoriseTokens from "./helpers/authorise-tokens"
77

8-
Vue.config.productionTip = false
9-
108
new Vue({
119
el: '#app',
1210
render: h => h(AppLayout),
1311
router,
14-
store
12+
store,
1513
})
1614

15+
// store.commit("auth/SET_GOTRUE", GoTrueAuth)
16+
17+
1718
restoreState()
1819
attemptToAuthoriseTokens()
1920

21+
Vue.config.productionTip = false

src/store/modules/auth.js

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
1+
import {Auth} from '../../helpers/init-auth.js'
12

2-
import GoTrue from "gotrue-js";
3-
4-
export const Auth = new GoTrue({
5-
APIUrl: "https://simple-vue-netlify-auth.netlify.com/.netlify/identity",
6-
audience: "",
7-
setCookie: false
8-
});
3+
console.log(Auth)
94

105
let saveState = function (key, state) {
116
window.localStorage.setItem(key, JSON.stringify(state));
@@ -51,12 +46,14 @@ export default {
5146

5247
state() {
5348
return {
54-
testData: "Hello!",
55-
currentUser:null
49+
testData: "some test data",
50+
currentUser:null,
5651
}
5752
},
5853
getters: {
59-
54+
55+
testData : state => state.testData,
56+
6057
// When currentUser has data loggedIn will return true
6158
loggedIn: state => !!state.currentUser,
6259

@@ -72,6 +69,9 @@ export default {
7269
updateTestData(state, value) {
7370
state.testData = value
7471
},
72+
SET_GOTRUE(state, value){
73+
Auth = value
74+
},
7575
SET_CURRENT_USER(state, value) {
7676
state.currentUser = value;
7777
saveState("auth.currentUser", value)
@@ -86,6 +86,10 @@ export default {
8686
updateTestDataAction({ commit }, value) {
8787
commit('updateTestData', value)
8888
},
89+
90+
updateAuth({ commit }, value) {
91+
commit('updateTestData', value)
92+
},
8993

9094
attemptLogin({ commit }, credentials) {
9195
console.log(`attempting login for ${credentials.email}`)
@@ -188,7 +192,7 @@ export default {
188192
})
189193
},
190194

191-
attemptLogout({commit}){
195+
attemptLogout({commit,}){
192196

193197
commit("SET_CURRENT_USER", null)
194198

0 commit comments

Comments
 (0)