Skip to content

Conversation

@boutell
Copy link
Member

@boutell boutell commented Apr 26, 2024

Demonstrates how to distinguish the guest admin bar experience e.g. just show a logout button with custom (in this case very minimal) markup.

PoC only, do not merge.

@linear
Copy link

linear bot commented Apr 26, 2024

@@ -0,0 +1,153 @@
<template>
<div
Copy link
Member Author

@boutell boutell Apr 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Conditionally emit different markup when the user is a guest.

>
<button @click="logout">Log Out</button>
</div>
<div v-else
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The HTML from here down is unmodified. There are a few changes separately called out in the script section.

moduleOptions() {
return window.apos.adminBar;
},
guest() {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exposes the fact that the user is a guest. See also the getBrowserData extension below.

}
},
mounted() {
if (!this.guest) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The last change in this file: don't invoke a method that manipulates markup we won't have for guests.

getBrowserData(_super, req) {
const data = _super(req);
if (data.user) {
data.user.role = req.user.role;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't expose the logged-in user's role on the front end by default, so add that information.

@@ -0,0 +1,153 @@
<template>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

99% of this file is directly copied from the original in the apostrophe module, see below for the changes.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could place this file in any module, as long as it is in the ui/apos/components subdirectory of that module. I chose the project-level modules/@apostrophecms/admin-bar folder to make it easier to find this override later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants