@thecodeorigin/auth 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@thecodeorigin/auth",
3
3
  "configKey": "auth",
4
- "version": "0.0.4",
4
+ "version": "0.0.5",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "3.6.1"
package/dist/module.mjs CHANGED
@@ -29,6 +29,7 @@ const module$1 = defineNuxtModule({
29
29
  addServerHandler({ route: routes.signOut, handler: resolver.resolve("./runtime/server/routes/sign-out.get") });
30
30
  for (const [route, file] of [
31
31
  ["/api/_auth/session", "session.get"],
32
+ ["/api/_auth/sign-out", "sign-out.post"],
32
33
  ["/api/_auth/organizations", "organizations.get"],
33
34
  ["/api/_auth/organizations/switch", "organizations/switch.post"],
34
35
  ["/api/_auth/impersonatable-users", "impersonatable-users.get"],
@@ -101,6 +101,6 @@ export declare function useAuth(): {
101
101
  impersonate: (userId: string) => Promise<void>;
102
102
  stopImpersonating: () => Promise<void>;
103
103
  signIn: (redirect?: string) => string | false | void | import("vue-router").RouteLocationAsRelativeGeneric | import("vue-router").RouteLocationAsPathGeneric | Promise<false | void | import("vue-router").NavigationFailure>;
104
- signOut: () => string | false | void | import("vue-router").RouteLocationAsRelativeGeneric | import("vue-router").RouteLocationAsPathGeneric | Promise<false | void | import("vue-router").NavigationFailure>;
104
+ signOut: () => Promise<void>;
105
105
  refresh: () => Promise<void>;
106
106
  };
@@ -38,8 +38,10 @@ export function useAuth() {
38
38
  { external: true }
39
39
  );
40
40
  }
41
- function signOut() {
42
- return navigateTo(routes.signOut, { external: true });
41
+ async function signOut() {
42
+ await $fetch("/api/_auth/sign-out", { method: "POST" }).catch(() => {
43
+ });
44
+ session.value = null;
43
45
  }
44
46
  return {
45
47
  session,
@@ -0,0 +1,4 @@
1
+ declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<{
2
+ ok: boolean;
3
+ }>>;
4
+ export default _default;
@@ -0,0 +1,6 @@
1
+ import { defineEventHandler } from "h3";
2
+ import { destroySession } from "../../utils/session.js";
3
+ export default defineEventHandler(async (event) => {
4
+ await destroySession(event);
5
+ return { ok: true };
6
+ });
@@ -1,31 +1,8 @@
1
- import { defineEventHandler, getRequestHost, getRequestProtocol, sendRedirect } from "h3";
1
+ import { defineEventHandler, sendRedirect } from "h3";
2
2
  import { useRuntimeConfig } from "nitropack/runtime";
3
- import { $fetch } from "ofetch";
4
- import { withQuery } from "ufo";
5
3
  import { destroySession } from "../utils/session.js";
6
4
  export default defineEventHandler(async (event) => {
7
- const { auth: runtimeConfig, public: { auth: publicRuntimeConfig } } = useRuntimeConfig();
8
- const rec = await destroySession(event);
9
- if (rec?.accessToken) {
10
- await $fetch(`https://${publicRuntimeConfig.domain}/api/auth/oauth2/revoke`, {
11
- method: "POST",
12
- body: new URLSearchParams({
13
- token: rec.refreshToken ?? rec.accessToken,
14
- token_type_hint: rec.refreshToken ? "refresh_token" : "access_token",
15
- client_id: publicRuntimeConfig.clientId,
16
- client_secret: runtimeConfig.clientSecret
17
- }).toString(),
18
- headers: { "Content-Type": "application/x-www-form-urlencoded" }
19
- }).catch(() => {
20
- });
21
- }
22
- const postLogoutRedirectUri = `${getRequestProtocol(event)}://${getRequestHost(event)}${publicRuntimeConfig.routes.home}`;
23
- if (rec?.idToken) {
24
- return sendRedirect(event, withQuery(`https://${publicRuntimeConfig.domain}/api/auth/oauth2/end-session`, {
25
- id_token_hint: rec.idToken,
26
- client_id: publicRuntimeConfig.clientId,
27
- post_logout_redirect_uri: postLogoutRedirectUri
28
- }));
29
- }
5
+ const { public: { auth: publicRuntimeConfig } } = useRuntimeConfig();
6
+ await destroySession(event);
30
7
  return sendRedirect(event, publicRuntimeConfig.routes.home);
31
8
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@thecodeorigin/auth",
3
3
  "type": "module",
4
- "version": "0.0.4",
4
+ "version": "0.0.5",
5
5
  "private": false,
6
6
  "description": "THECODEORIGIN Authentication Portal client module",
7
7
  "repository": "https://github.com/thecodeorigin/auth",