Skip to content

Commit

Permalink
useCurrentUserStore() has been renamed to useCurrentUser()
Browse files Browse the repository at this point in the history
  • Loading branch information
rizen committed May 2, 2024
1 parent 118c857 commit 45bf2ac
Show file tree
Hide file tree
Showing 20 changed files with 33 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { isObject, isUndefined } from '#ving/utils/identify.mjs';

const query = { includeOptions: true, includeMeta: true, includeLinks: true };

export const useCurrentUserStore = defineStore('currentUser', {
export const useCurrentUser = defineStore('currentUser', {
state: () => ({
props: {},
meta: {},
Expand Down Expand Up @@ -71,6 +71,18 @@ export const useCurrentUserStore = defineStore('currentUser', {
this.setState(response.data);
return response;
},
async save(key) {
const valuesToSave = {};
valuesToSave[key] = this.props[key];
const response = await useRest(this.links?.self?.href, {
method: 'put',
body: valuesToSave,
query,
});
if (response.data)
this.setState(response.data);
return response;
},
async create(newUser) {
const response = await useRest(`/api/${useRestVersion()}/user`, {
method: 'post',
Expand Down
2 changes: 1 addition & 1 deletion composables/ving/useMessageBus.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/
export default async function useMessageBus() {
const notify = useNotifyStore();
const currentUser = useCurrentUserStore();
const currentUser = useCurrentUser();

let reconnectFrequencySeconds = 1;
let bus = null;
Expand Down
2 changes: 1 addition & 1 deletion composables/ving/userSettingsButtons.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

export default () => {
const currentUser = useCurrentUserStore();
const currentUser = useCurrentUser();
const buttons = computed(() => {
const out = [
{ label: 'Sign Out', to: '/user/logout', icon: 'ph:door', severity: 'primary' },
Expand Down
2 changes: 1 addition & 1 deletion composables/ving/userSettingsLinks.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

export default () => {
const currentUser = useCurrentUserStore();
const currentUser = useCurrentUser();
const links = computed(() => {
const out = [
{ label: 'Profile', to: '/user/settings', icon: 'ph:user' },
Expand Down
2 changes: 1 addition & 1 deletion layouts/default.vue
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@

<script setup>
const config = useRuntimeConfig();
const currentUser = useCurrentUserStore();
const currentUser = useCurrentUser();
await currentUser.isAuthenticated();
onMounted(async () => {
// subscribe to message bus
Expand Down
2 changes: 1 addition & 1 deletion middleware/admin.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ouch } from '#ving/utils/ouch.mjs';
export default defineNuxtRouteMiddleware(async (to, from) => {
const currentUser = useCurrentUserStore();
const currentUser = useCurrentUser();
if (!currentUser.props?.admin) {
throw ouch(403, 'You must be an admin to view this.');
}
Expand Down
2 changes: 1 addition & 1 deletion middleware/auth.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export default defineNuxtRouteMiddleware(async (to, from) => {
const currentUser = useCurrentUserStore();
const currentUser = useCurrentUser();
const isAuthenticated = await currentUser.isAuthenticated();
if (!isAuthenticated) {
return await navigateTo(`/user/login?redirectAfter=${to.fullPath}`);
Expand Down
2 changes: 1 addition & 1 deletion pages/user/[id]/profile.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ await user.fetch()

onBeforeRouteLeave(() => user.dispose());

const currentUser = useCurrentUserStore();
const currentUser = useCurrentUser();


</script>
2 changes: 1 addition & 1 deletion pages/user/admin/[id].vue
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ onBeforeRouteLeave(() => user.dispose());
async function become() {
await user.call('post', user.links?.self.href + '/become', undefined, {
async onSuccess() {
const currentUser = useCurrentUserStore();
const currentUser = useCurrentUser();
currentUser.fetch();
await navigateTo('/');
}
Expand Down
2 changes: 1 addition & 1 deletion pages/user/create.vue
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
<script setup>
let newUser = ref({ username: '', email: '', realName: '', password: '', password2: '' });
const config = useRuntimeConfig();
const currentUser = useCurrentUserStore();
const currentUser = useCurrentUser();
async function createAccount() {
const response = await currentUser.create(newUser.value);
Expand Down
2 changes: 1 addition & 1 deletion pages/user/login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ import { isString } from '#ving/utils/identify.mjs';
let login = ref('');
let password = ref('');
const config = useRuntimeConfig();
const currentUser = useCurrentUserStore();
const currentUser = useCurrentUser();
async function tryLogin() {
const response = await currentUser.login(login.value, password.value);
Expand Down
2 changes: 1 addition & 1 deletion pages/user/logout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { sleep } from '#ving/utils/sleep.mjs';
definePageMeta({
middleware: 'auth'
});
const currentUser = useCurrentUserStore();
const currentUser = useCurrentUser();
await currentUser.logout();
await sleep(1000 * 5);
await navigateTo('/');
Expand Down
2 changes: 1 addition & 1 deletion pages/user/must-verify-email.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<script setup>
const config = useRuntimeConfig();
onMounted(async () => {
const currentUser = useCurrentUserStore();
const currentUser = useCurrentUser();
const query = useRoute().query;
await currentUser.sendVerifyEmail(query.redirectAfter?.toString());
});
Expand Down
2 changes: 1 addition & 1 deletion pages/user/settings/account.vue
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ definePageMeta({
middleware: ['auth']
});
const notify = useNotifyStore();
const currentUser = useCurrentUserStore();
const currentUser = useCurrentUser();
const links = userSettingsLinks();
const buttons = userSettingsButtons();
const newPassword = ref({ password: '', password2: '' });
Expand Down
2 changes: 1 addition & 1 deletion pages/user/settings/apikeys.vue
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
definePageMeta({
middleware: ['auth']
});
const currentUser = useCurrentUserStore();
const currentUser = useCurrentUser();
const links = userSettingsLinks();
const buttons = userSettingsButtons();
const apikeys = useVingKind({
Expand Down
2 changes: 1 addition & 1 deletion pages/user/settings/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
definePageMeta({
middleware: ['auth']
});
const currentUser = useCurrentUserStore();
const currentUser = useCurrentUser();
const links = userSettingsLinks();
const buttons = userSettingsButtons();
</script>
2 changes: 1 addition & 1 deletion pages/user/settings/preferences.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
definePageMeta({
middleware: ['auth']
});
const currentUser = useCurrentUserStore();
const currentUser = useCurrentUser();
const links = userSettingsLinks();
const buttons = userSettingsButtons();
</script>
2 changes: 1 addition & 1 deletion pages/user/verify-email.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<script setup>
const config = useRuntimeConfig();
const message = ref('Please wait while we verify your email address.');
const currentUser = useCurrentUserStore();
const currentUser = useCurrentUser();
const query = useRoute().query;
await currentUser.verifyEmail(query.verify?.toString());
if (currentUser.props?.verifiedEmail) {
Expand Down
1 change: 1 addition & 0 deletions ving/docs/change-log.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ outline: deep
* NOTE: useDateTime() no longer exists, just use formatDate(), formatDateTime(), and formatTimeAgo() directly.
* NOTE: restVersion() has been renamed to useRestVersion(), update your codebase appropriately.
* NOTE: adminLinks() has been renamed to useAdminLinks(), update your codebase appropriately.
* NOTE: useCurrentUserStore() has been renamed to useCurrentUser(), update your codebase appropriately.

## 2024-04-29
* Implemented: reformat page generator to use panel components on view and edit #139
Expand Down
4 changes: 2 additions & 2 deletions ving/docs/subsystems/ui.md
Original file line number Diff line number Diff line change
Expand Up @@ -371,11 +371,11 @@ Returns a data structure for use with the `PanelNav` component.
const links = useAdminLinks();
```

### currentUserStore()
### useCurrentUser()
Gets you the currently logged in user.

```js
const user = useCurrentUserStore();
const user = useCurrentUser();
if (await user.isAuthenticated()) {
// do logged in user stuff
}
Expand Down

0 comments on commit 45bf2ac

Please sign in to comment.