cobras-auth-nuxt 1.0.0 → 1.0.2

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
@@ -4,7 +4,7 @@
4
4
  "compatibility": {
5
5
  "nuxt": ">=3.0.0"
6
6
  },
7
- "version": "1.0.0",
7
+ "version": "1.0.1",
8
8
  "builder": {
9
9
  "@nuxt/module-builder": "0.8.4",
10
10
  "unbuild": "unknown"
@@ -1,4 +1,4 @@
1
- import { defineNuxtRouteMiddleware, useRuntimeConfig, useState, navigateTo } from "#imports";
1
+ import { defineNuxtRouteMiddleware, useRuntimeConfig, useState, navigateTo, useRequestURL } from "#imports";
2
2
  export default defineNuxtRouteMiddleware(async (to) => {
3
3
  const config = useRuntimeConfig();
4
4
  const authConfig = config.public.cobrasAuth;
@@ -26,10 +26,11 @@ export default defineNuxtRouteMiddleware(async (to) => {
26
26
  if (typeof window !== "undefined") {
27
27
  redirectUrl = window.location.href;
28
28
  } else {
29
- redirectUrl = to.fullPath;
29
+ const requestUrl = useRequestURL();
30
+ redirectUrl = requestUrl.href;
30
31
  }
31
32
  return navigateTo(
32
- `${authConfig.authServiceUrl}/login?redirect_uri=${encodeURIComponent(redirectUrl)}`,
33
+ `${authConfig.authServiceUrl}/api/auth/authorize?redirect_uri=${encodeURIComponent(redirectUrl)}`,
33
34
  { external: true }
34
35
  );
35
36
  }
@@ -1,4 +1,4 @@
1
- import { defineNuxtRouteMiddleware, useRuntimeConfig, useState, navigateTo } from "#imports";
1
+ import { defineNuxtRouteMiddleware, useRuntimeConfig, useState, navigateTo, useRequestURL } from "#imports";
2
2
  export default defineNuxtRouteMiddleware(async (to) => {
3
3
  const config = useRuntimeConfig();
4
4
  const authConfig = config.public.cobrasAuth;
@@ -10,9 +10,15 @@ export default defineNuxtRouteMiddleware(async (to) => {
10
10
  return;
11
11
  }
12
12
  if (!state.value?.user) {
13
- const currentUrl = typeof window !== "undefined" ? window.location.href : to.fullPath;
13
+ let currentUrl;
14
+ if (typeof window !== "undefined") {
15
+ currentUrl = window.location.href;
16
+ } else {
17
+ const requestUrl = useRequestURL();
18
+ currentUrl = requestUrl.href;
19
+ }
14
20
  return navigateTo(
15
- `${authConfig.authServiceUrl}/login?redirect_uri=${encodeURIComponent(currentUrl)}`,
21
+ `${authConfig.authServiceUrl}/api/auth/authorize?redirect_uri=${encodeURIComponent(currentUrl)}`,
16
22
  { external: true }
17
23
  );
18
24
  }
@@ -57,8 +57,8 @@ export default defineNuxtPlugin(async (nuxtApp) => {
57
57
  }
58
58
  function login(redirect) {
59
59
  const currentUrl = redirect || window.location.href;
60
- const loginUrl = `${authConfig.authServiceUrl}/login?redirect_uri=${encodeURIComponent(currentUrl)}`;
61
- window.location.href = loginUrl;
60
+ const authorizeUrl = `${authConfig.authServiceUrl}/api/auth/authorize?redirect_uri=${encodeURIComponent(currentUrl)}`;
61
+ window.location.href = authorizeUrl;
62
62
  }
63
63
  async function logout() {
64
64
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cobras-auth-nuxt",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "Nuxt 3/4 module for Cobras Auth service - supports internal (SSO) and public modes",
5
5
  "repository": {
6
6
  "type": "git",