DEV Community

Kevin Jump
Kevin Jump

Posted on • Edited on

Battle scarred developer's guide to Umbraco v17 - Entry Points

All the code for this series of posts is available in the DoStuffWithUmbraco Repository on GitHub

So now that bundles have replaced entry points as the place to integrate your Umbraco extension, do we still need entry points?

Yes, i most cases you will still need an entry point, to initialize things like the authentication for your client to talk to the server. or if you are feeling really mischievous to unload other entries from the umbraco registry !

Register your entry point via a manifest.

all the extension template will do this one for you, but to show the process

export const manifests: Array<UmbExtensionManifest> = [
  {
    name: "Do Stuff Client Entrypoint",
    alias: "DoStuff.Client.Entrypoint",
    type: "backofficeEntryPoint",
    js: () => import("./entrypoint.js"),
  },
];
Enter fullscreen mode Exit fullscreen mode

this is then imported and registered via your bundle.manifest.ts file.

Auth.

The examples that you get with the templates contain most of the code you will need here for authentication.

 _host.consumeContext(UMB_AUTH_CONTEXT, async (authContext) => {
    // Get the token info from Umbraco
    const config = authContext?.getOpenApiConfiguration();

    client.setConfig({
      auth: config?.token ?? undefined,
      baseUrl: config?.base ?? "",
      credentials: config?.credentials ?? "same-origin",
    });
  });
};
Enter fullscreen mode Exit fullscreen mode

As we've said in another post we like to add a bit - which keeps the token fresh for each request.

    // client interceptor will get the latest token for the auth
    // context for a request, so if the token has been refreshed
    // since we first got it, we'll still have a valid token.
    client.interceptors.request.use(async (request, _options) => {
      const token = await authContext?.getLatestToken();
      request.headers.set("Authorization", `Bearer ${token}`);
      return request;
    });
Enter fullscreen mode Exit fullscreen mode

honesty - i am not 100% sure this extra bit is in fact needed - it's something we might revisit.

Unregistering things!

So your onInit method runs when your extension is loaded, and you can if you want start to manipulate Umbraco's register, you could for example remove the welcome dashboard this way.

extensionRegistry.unregister('Umb.Dashboard.UmbracoNews');
Enter fullscreen mode Exit fullscreen mode

Be carefull! removing things from the register might well make bits of the umbraco backoffice unstable.

Top comments (0)