Skip to content

Commit

Permalink
fix(space-nuxt-base): move plugin type to the top level of app config (
Browse files Browse the repository at this point in the history
  • Loading branch information
eunjae-lee authored Jul 22, 2024
1 parent 778d6d9 commit cbfcedb
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 6 deletions.
5 changes: 3 additions & 2 deletions space-plugins/nuxt-base/app.config.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { AppBridgeConfig } from './types/appBridge';
import type { AppBridgeConfig, PluginType } from './types/appBridge';

export default defineAppConfig({
type: 'space-plugin',
appBridge: {
type: 'space-plugin',
enabled: false,
oauth: true,
origin: 'https://app.storyblok.com',
Expand All @@ -17,6 +17,7 @@ export default defineAppConfig({

declare module '@nuxt/schema' {
interface AppConfigInput {
type: PluginType;
appBridge: AppBridgeConfig;
auth: AuthConfig;
}
Expand Down
4 changes: 2 additions & 2 deletions space-plugins/nuxt-base/composables/useAppBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ const useAppBridgeAuth = ({
const slug = getSlug();

try {
const type = appConfig.appBridge.type;
const type = appConfig.type;
const payload = createValidateMessagePayload({ type, slug });

postMessageToParent(payload);
Expand Down Expand Up @@ -205,7 +205,7 @@ const useOAuth = () => {

const sendBeginOAuthMessageToParent = (redirectTo: string) => {
const slug = getSlug();
const type = appConfig.appBridge.type;
const type = appConfig.type;
const payload = createOAuthInitMessagePayload({ type, slug, redirectTo });
postMessageToParent(payload);
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
export default defineEventHandler(async (event) => {
const appConfig = useAppConfig();
if (
event.path === '/401' &&
event.headers.get('Referer') === 'https://app.storyblok.com/'
) {
return await sendRedirect(
event,
'https://app.storyblok.com/oauth/app_redirect',
appConfig.type === 'tool-plugin'
? 'https://app.storyblok.com/oauth/tool_redirect'
: 'https://app.storyblok.com/oauth/app_redirect',
302,
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ export default defineEventHandler(async (event) => {
const appConfig = useAppConfig();

const appSession = await getAppSession(event);
if (!appSession) {
return;
}

event.context.appSession = appSession;

const afterAuthenticated = appConfig.auth.middleware?.afterAuthenticated;
Expand Down
1 change: 0 additions & 1 deletion space-plugins/nuxt-base/types/appBridge.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export type AppBridgeConfig = {
type: PluginType;
enabled: boolean;
oauth: boolean;
origin?: string;
Expand Down

0 comments on commit cbfcedb

Please sign in to comment.