Skip to content

Commit 5966bde

Browse files
authored
Merge pull request #126 from buggregator/hotfix/auth
Fixes some auth problems
2 parents e6c0a89 + f28669b commit 5966bde

File tree

23 files changed

+254
-99
lines changed

23 files changed

+254
-99
lines changed

layouts/default.vue

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { useEvents } from "~/src/shared/lib/use-events";
2121
import { useSettings } from "~/src/shared/lib/use-settings";
2222
import SfdumpWrap from "~/src/shared/lib/vendor/dumper";
2323
import { version } from "../package.json";
24+
import {useProfileStore} from "~/stores/profile";
2425
import { useSettingsStore } from "~/stores/settings";
2526
2627
export default defineComponent({
@@ -32,14 +33,14 @@ export default defineComponent({
3233
SfdumpWrap(window.document);
3334
3435
const settingsStore = useSettingsStore();
36+
const profileStore = useProfileStore();
3537
const { themeType, isFixedHeader } = storeToRefs(settingsStore);
3638
3739
const {
38-
api: { getVersion, getProfile },
40+
api: { getVersion },
3941
} = useSettings();
4042
4143
const apiVersion = await getVersion();
42-
const profile = await getProfile();
4344
4445
const { events } = useEvents();
4546
@@ -57,7 +58,7 @@ export default defineComponent({
5758
? `v${apiVersion}`
5859
: `@${apiVersion}`,
5960
clientVersion,
60-
profile,
61+
profile: profileStore.profile,
6162
};
6263
},
6364
});

middleware/auth.global.ts

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,30 @@
11
import { useNuxtApp, navigateTo } from "#app"
2+
import { useSettings } from "~/src/shared/lib/use-settings";
3+
import { useProfileStore } from "~/stores/profile"
24

3-
export default defineNuxtRouteMiddleware(async (to, from) => {
5+
export default defineNuxtRouteMiddleware(async (to) => {
46
const app = useNuxtApp()
5-
const {localStorage} = window;
67

78
if (!app.$appSettings.auth.enabled) {
8-
return;
9+
return
910
}
1011

11-
// todo: move token to a store
12-
if (to.name !== 'login' && !app.$authToken.token) {
13-
return navigateTo('/login');
12+
const store = useProfileStore()
13+
store.fetchToken()
14+
15+
if (store.isAuthenticated) {
16+
const {api: {getProfile}} = useSettings();
17+
const profile = await getProfile();
18+
store.setProfile(profile)
19+
return
20+
}
21+
22+
if (to.name !== 'login' && !store.isAuthenticated) {
23+
return navigateTo('/login')
1424
}
1525

1626
if (to.name === 'login' && to?.query?.token) {
17-
localStorage?.setItem('token', to.query.token);
18-
// todo: use store
19-
app.$authToken.token = to.query.token;
20-
return navigateTo('/');
27+
store.setToken(to.query.token)
28+
return navigateTo('/')
2129
}
2230
})

pages/login.vue

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,18 @@
22
import { useNuxtApp, navigateTo } from "#app"
33
import { REST_API_URL } from "~/src/shared/lib/io";
44
import { IconSvg } from "~/src/shared/ui";
5+
import {useProfileStore} from "~/stores/profile";
56
67
definePageMeta({
78
layout: 'blank'
89
})
910
1011
const app = useNuxtApp()
12+
const store = useProfileStore()
13+
14+
if (store.isAuthenticated) {
15+
await navigateTo('/')
16+
}
1117
1218
const redirect = async () => {
1319
await navigateTo(`${REST_API_URL}/${app.$appSettings.auth.login_url}`, {
@@ -29,7 +35,8 @@ const redirect = async () => {
2935
Continue to SSO
3036
</button>
3137
</div>
32-
<div class="login-form-right-block"
38+
<div
39+
class="login-form-right-block"
3340
style="background: url('/bg.jpg'); background-size: cover; background-position: center center;">
3441
</div>
3542
</div>

pages/settings.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ export default defineComponent({
7979
const { changeTheme, changeNavbar } = settingsStore;
8080
const { themeType, isFixedHeader } = storeToRefs(settingsStore);
8181
82+
console.log(settingsStore)
83+
8284
return {
8385
themeType,
8486
isFixedHeader,

pages/smtp/[id].vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import { useFetch, useNuxtApp, useRoute, useRouter } from "#app"; // eslint-disa
2828
import { PageHeader } from "~/src/widgets/ui";
2929
import { useSmtp } from "~/src/entities/smtp";
3030
import type { SMTP } from "~/src/entities/smtp/types";
31-
import { REST_API_URL } from "~/src/shared/lib/io";
31+
import { htmlEncode } from "~/src/shared/lib/helpers";
3232
import { useEvents } from "~/src/shared/lib/use-events";
3333
import type { EventId, ServerEvent } from "~/src/shared/types";
3434
import { SmtpPage } from "~/src/screens/smtp";
@@ -63,7 +63,7 @@ export default defineComponent({
6363
serverEvent: event,
6464
pending,
6565
eventId,
66-
html: `<iframe src="${REST_API_URL}/api/smtp/${eventId}/html"/>`,
66+
html: `<iframe srcdoc="${htmlEncode(event.value.payload.html)}"/>`,
6767
clearEvent: () => events.removeById(eventId),
6868
};
6969
},

plugins/auth.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import { useSettings } from "~/src/shared/lib/use-settings";
22

3-
const {localStorage} = window;
4-
53
// todo: use store for token
64
export default defineNuxtPlugin(async () => {
75
const {
@@ -25,18 +23,16 @@ export default defineNuxtPlugin(async () => {
2523
if (!settings.auth.enabled) {
2624
return {
2725
provide: {
28-
authToken: {token: null},
29-
appSettings: settings
26+
appSettings: settings,
27+
authToken: {token: null}
3028
}
3129
}
3230
}
3331

34-
const token: string | null = localStorage?.getItem('token')
35-
3632
return {
3733
provide: {
38-
authToken: {token},
39-
appSettings: settings
34+
appSettings: settings,
35+
authToken: {token: null}
4036
}
4137
}
4238
})

src/entities/ray/mocks/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import rayBooleanFalseMock from './ray-boolean-false.json';
2+
import rayBooleanTrueMock from './ray-boolean-true.json';
13
import rayCallerMock from './ray-caller.json';
24
import rayCarbonMock from './ray-carbon.json';
35
import rayColorMock from './ray-color.json';
@@ -18,8 +20,6 @@ import raySizeMock from './ray-size.json';
1820
import rayTableMock from './ray-table.json';
1921
import rayTextMock from './ray-text.json';
2022
import rayTraceMock from './ray-trace.json';
21-
import rayBooleanTrueMock from './ray-boolean-true.json';
22-
import rayBooleanFalseMock from './ray-boolean-false.json';
2323

2424
export {
2525
rayCallerMock,

src/entities/smtp/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export interface SMTPUser {
44
name: string,
55
email: string,
66
}
7+
78
export interface SMTP {
89
id: string,
910
from: SMTPUser[],

src/screens/smtp/ui/smtp-page-preview/smtp-page-preview.stories.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { Meta, StoryObj } from "@storybook/vue3";
22
import type { ComponentProps } from "vue-component-type-helpers";
3+
import {htmlEncode} from "~/src/shared/lib/helpers";
34
import { HTMLCode } from '~/src/shared/mocks'
45
import SmtpPagePreview from './smtp-page-preview.vue';
56

@@ -13,7 +14,11 @@ export default {
1314
args,
1415
};
1516
},
16-
template: `<SmtpPagePreview v-bind="args">${HTMLCode}</SmtpPagePreview>`,
17+
template: `<div style="height: 100vh">
18+
<SmtpPagePreview v-bind="args">
19+
<iframe srcdoc="<html>${htmlEncode(HTMLCode)}</html>"></iframe>
20+
</SmtpPagePreview>
21+
</div>`,
1722
})
1823
} as Meta<typeof SmtpPagePreview>;
1924

src/screens/smtp/ui/smtp-page-preview/smtp-page-preview.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ const currentDevice = ref(props.device);
8383
}
8484
8585
.smtp-page-preview__device {
86-
@apply flex-1 flex flex-col items-center bg-gray-50 dark:bg-gray-900;
86+
@apply flex flex-col items-center bg-gray-50 dark:bg-gray-900;
8787
8888
html.dark & {
8989
@apply text-gray-800;

0 commit comments

Comments
 (0)