Skip to content

Commit be7857b

Browse files
committed
Add support for auto signing in custom Admin UI
1 parent 85ef836 commit be7857b

File tree

3 files changed

+494
-439
lines changed

3 files changed

+494
-439
lines changed

MyApp/Components/Pages/Home.razor

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,23 @@
1111
<p class="mx-auto mt-3 max-w-md text-base text-gray-500 sm:text-lg md:mt-5 md:max-w-3xl md:text-xl">
1212
Welcome to your new Blazor Vue App, checkout links below to get started:
1313
</p>
14-
<div class="mx-auto mt-5 max-w-md sm:flex sm:justify-center md:mt-8">
14+
<div class="mx-auto mt-5 sm:flex sm:justify-center md:mt-8">
1515
<div class="rounded-md shadow">
16-
<a href="https://blazor-gallery.servicestack.net/" class="flex w-full items-center justify-center rounded-md border border-transparent bg-indigo-600 px-8 py-3 text-base font-medium text-white hover:bg-indigo-700 md:py-4 md:px-10 md:text-lg">
16+
<a href="/admin/?user=admin@email.com&pass=p@55wOrd" class="flex w-full items-center justify-center rounded-md border border-transparent bg-white dark:bg-gray-800 dark:border-gray-600 px-8 py-3 text-base font-medium text-indigo-600 dark:text-gray-100 hover:bg-gray-50 dark:hover:bg-gray-700 md:py-4 md:px-10 md:text-lg">
17+
Admin UI
18+
</a>
19+
</div>
20+
<div class="mt-3 rounded-md shadow sm:mt-0 sm:ml-3">
21+
<a href="https://blazor-gallery.servicestack.net/" class="flex w-full items-center justify-center rounded-md border border-transparent bg-purple-600 px-8 py-3 text-base font-medium text-white hover:bg-purple-700 md:py-4 md:px-10 md:text-lg">
1722
Blazor Gallery
1823
</a>
1924
</div>
2025
<div class="mt-3 rounded-md shadow sm:mt-0 sm:ml-3">
21-
<a href="https://docs.servicestack.net/vue/" class="flex w-full items-center justify-center rounded-md border border-transparent bg-white dark:bg-gray-800 dark:border-gray-600 px-8 py-3 text-base font-medium text-indigo-600 dark:text-gray-100 hover:bg-gray-50 dark:hover:bg-gray-700 md:py-4 md:px-10 md:text-lg">
26+
<a href="https://docs.servicestack.net/vue/" class="flex w-full items-center justify-center rounded-md border border-transparent bg-green-600 px-8 py-3 text-base font-medium text-white hover:bg-green-700 md:py-4 md:px-10 md:text-lg">
2227
Vue Gallery
2328
</a>
2429
</div>
30+
2531
</div>
2632
</div>
2733
</div>

MyApp/wwwroot/admin/index.html

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@
5858
</sidebar-layout>
5959
<main class="lg:pl-72">
6060
<div v-if="init" class="px-4 sm:px-6 lg:px-8">
61-
<sign-in v-if="!user"></sign-in>
61+
<div v-if="!user">
62+
<sign-in></sign-in>
63+
</div>
6264
<div v-else>
6365
<h1 class="hidden lg:block pt-4 mb-2 text-3xl font-bold leading-tight tracking-tight text-gray-900">{{ activeSection.title }}</h1>
6466
<component :key="refreshKey" :is="activeSection.component" @nav="navTo" :type="activeSection.type"></component>
@@ -69,7 +71,7 @@ <h1 class="hidden lg:block pt-4 mb-2 text-3xl font-bold leading-tight tracking-t
6971

7072
<script type="module">
7173
import { createApp, ref, onMounted, shallowRef } from "vue"
72-
import { JsonApiClient, leftPart, rightPart, appendQueryString, humanize } from "@servicestack/client"
74+
import { JsonApiClient, leftPart, rightPart, appendQueryString, humanize, queryString } from "@servicestack/client"
7375
import ServiceStackVue, { useClient, useAuth, useMetadata } from "@servicestack/vue"
7476
import { Authenticate, AdminData } from "dtos.mjs"
7577
import * as Sections from "./sections/index.mjs"
@@ -167,10 +169,28 @@ <h2 class="mt-4 text-3xl sm:text-4xl text-slate-900 font-extrabold tracking-tigh
167169
window.addEventListener('popstate', event => {
168170
navTo(event.state?.section || getSection(), {}, false)
169171
})
172+
173+
// Auto Sign In ?user=...&pass=...
174+
if (location.search) {
175+
const q = queryString(location.search)
176+
if (q.user && q.pass) {
177+
const api = await client.api(new Authenticate({
178+
provider: 'credentials',
179+
userName: q.user,
180+
password: q.pass,
181+
}))
182+
if (api.succeeded) {
183+
signIn(api.response)
184+
history.replaceState({}, null, leftPart(location.href, '?'))
185+
}
186+
}
187+
}
170188

171-
const api = await client.api(new Authenticate())
172-
if (api.succeeded) {
173-
signIn(api.response)
189+
if (!user.value) {
190+
const api = await client.api(new Authenticate())
191+
if (api.succeeded) {
192+
signIn(api.response)
193+
}
174194
}
175195
init.value = true
176196
})

0 commit comments

Comments
 (0)