Skip to content

Commit ea76050

Browse files
authored
Merge pull request #28 from sheibeck/develop
Develop
2 parents 33286f7 + b3ead0c commit ea76050

9 files changed

Lines changed: 224 additions & 94 deletions

File tree

src/App.vue

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,9 @@ import { computed, onMounted } from 'vue';
4646
4747
const globalStore = useGlobalStore();
4848
const route = useRoute();
49-
const isLogin = computed(() => route.name === "login");
5049
51-
onMounted(() => {
52-
globalStore.getUserId();
50+
onMounted(async () => {
51+
await globalStore.getUserId();
5352
})
5453
5554
const isUserLoggedIn = computed( () => {

src/components/CharacterDetail.vue

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
Loading ...
44
</div>
55
<div v-else class="character mt-2">
6+
<div class="d-print-none d-flex justify-content-center" v-if="isGuest">
7+
<span class="text-danger">
8+
You must <a href="/login">sign in</a> to save characters. While not logged in, data you enter will be lost if you navigate away from this page.
9+
</span>
10+
</div>
611
<div class="gradient-background"></div>
712
<div class="page page1" v-if="pageNumber == 1 || isPrinting">
813
<div class="sheet-label">
@@ -78,7 +83,7 @@
7883
</div>
7984
</div>
8085

81-
<div class="d-print-none action-bar d-flex justify-content-end border-top p-1 mt-5" v-if="isAuthenticated">
86+
<div class="d-print-none action-bar d-flex justify-content-end border-top p-1 mt-5">
8287
<a href="/characters" type="button" class="btn btn-danger me-2">Close</a>
8388
<button type="button" class="btn btn-secondary me-2" @click="nextPage()"> View {{ pageLabel }}</button>
8489
<button type="button" class="btn btn-secondary me-2" @click="printCharacter()">Print</button>
@@ -122,7 +127,11 @@ const userId = ref<null|String>(null);
122127
const hasOverflowMoves = computed(() => character.value.startingMoves?.filter( (m: any) => m.isOverflow == true).length > 0);
123128
124129
const isOwner = computed(()=> {
125-
return character.value.userId === userId.value || characterId == "new-character";
130+
return userId.value !== null && (character.value.userId === userId.value || characterId == "new-character");
131+
});
132+
133+
const isGuest = computed(()=> {
134+
return userId.value == null;
126135
});
127136
128137
window.onafterprint = function(){

src/main.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import 'bootstrap/dist/js/bootstrap.bundle.min.js';
1010
import Vue3Toastify, { type ToastContainerOptions } from 'vue3-toastify';
1111
import { VueShowdownPlugin } from 'vue-showdown';
1212

13-
1413
awsconfig.oauth.redirectSignIn = `${window.location.origin}/`;
1514
awsconfig.oauth.redirectSignOut = `${window.location.origin}/`;
1615

src/services/lookupTableService.ts

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ const client = generateClient();
88

99
export const getProfessions = async() => {
1010

11-
const { data, errors} = await client.graphql({ query: queries.listProfessions, variables: { limit: 1000 } });
11+
const { data, errors} = await client.graphql({
12+
query: queries.listProfessions,
13+
variables: { limit: 1000 },
14+
authMode: 'iam',
15+
});
1216

1317
const professions = await data.listProfessions.items;
1418

@@ -23,7 +27,10 @@ export const getProfessions = async() => {
2327

2428
export const getAbilityScores = async() => {
2529

26-
const { data, errors} = await client.graphql({ query: queries.listAbilityScores});
30+
const { data, errors} = await client.graphql({
31+
query: queries.listAbilityScores,
32+
authMode: 'iam',
33+
});
2734

2835
return data.listAbilityScores.items.sort((a, b) => (a?.sortOrder ?? 0) - (b?.sortOrder ?? 0));
2936
}
@@ -39,7 +46,8 @@ export const getProfessionByName = async(name: string) => {
3946
}
4047
},
4148
limit: 1000,
42-
}
49+
},
50+
authMode: 'iam',
4351
});
4452

4553
const professsions = await result.data.listProfessions.items;
@@ -64,7 +72,8 @@ export const getBondsByProfession = async(profession: ProfessionType) => {
6472
}
6573
},
6674
limit: 1000,
67-
}
75+
},
76+
authMode: 'iam',
6877
});
6978

7079
return data.listBonds.items;
@@ -79,7 +88,8 @@ export const getMovesByProfession = async(profession: ProfessionType) => {
7988
}
8089
},
8190
limit: 1000,
82-
}
91+
},
92+
authMode: 'iam',
8393
});
8494

8595
return await data.listMoves.items;
@@ -94,7 +104,8 @@ export const getLooksByProfession = async(profession: ProfessionType) => {
94104
}
95105
} ,
96106
limit: 1000,
97-
}
107+
},
108+
authMode: 'iam',
98109
});
99110

100111
return data.listLooks.items;
@@ -109,7 +120,8 @@ export const getAlignmentsByProfession = async(profession: ProfessionType) => {
109120
}
110121
},
111122
limit: 1000,
112-
}
123+
},
124+
authMode: 'iam',
113125
});
114126

115127
return data.listAlignments.items;
@@ -124,7 +136,8 @@ export const getRaceByProfession = async(profession: ProfessionType) => {
124136
or: [{ profession: { eq: capitalizeWords(profession) } }, { profession: { eq: 'Any' } }]
125137
},
126138
limit: 1000,
127-
}
139+
},
140+
authMode: 'iam',
128141
});
129142

130143
return data.listRaces.items;
@@ -139,7 +152,8 @@ export const getStartingGearByProfession = async(profession: ProfessionType) =>
139152
and: [{ profession: { eq: capitalizeWords(profession) } }, { isStartingGear: { eq: true } }]
140153
},
141154
limit: 1000,
142-
}
155+
},
156+
authMode: 'iam',
143157
});
144158

145159
return data.listGears.items;

src/stores/globalStore.ts

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,37 +18,29 @@ export const useGlobalStore = defineStore('globalStore', () => {
1818
return true;
1919
}
2020
else {
21-
throw("Not authenticated");
21+
//is a guest user
22+
throw("guest users not allowed");
2223
}
2324

2425
}
2526
catch {
2627
currentUser.value = null;
27-
await router.push({ name: "login" });
28+
//await router.push({ name: "login" });
2829
return false;
2930
}
3031

3132
};
3233

3334
async function getUserId() {
34-
return new Promise<string|null>(async (resolve) => {
35-
try {
36-
const { username, userId, signInDetails } = await getCurrentUser();
37-
currentUser.value = userId;
38-
resolve(userId);
39-
}
40-
catch {
41-
try {
42-
const isAuthed = await isAuthenticated();
43-
if (!isAuthed) {
44-
throw("session expired");
45-
}
46-
}
47-
catch {
48-
await router.push({ name: "login" });
49-
}
50-
}
51-
});
35+
try {
36+
const { username, userId, signInDetails } = await getCurrentUser();
37+
currentUser.value = userId;
38+
return userId;
39+
}
40+
catch {
41+
currentUser.value = null;
42+
return null;
43+
}
5244
}
5345

5446
async function signOffUser() {

0 commit comments

Comments
 (0)