Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(space-nuxt-base): move plugin type to the top level of app config #70

Merged
merged 1 commit into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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