cobras-auth-nuxt 1.0.1 → 1.0.4
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
package/dist/module.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { defineNuxtModule, createResolver, addPlugin, addImports, addRouteMiddleware, addServerHandler, addComponent } from '@nuxt/kit';
|
|
1
|
+
import { defineNuxtModule, createResolver, addPlugin, addImports, addRouteMiddleware, addServerHandler, addComponent, extendPages } from '@nuxt/kit';
|
|
2
2
|
import { defu } from 'defu';
|
|
3
3
|
|
|
4
4
|
const module = defineNuxtModule({
|
|
@@ -99,6 +99,13 @@ const module = defineNuxtModule({
|
|
|
99
99
|
filePath: resolver.resolve("./runtime/components/CobrasDevTools.vue")
|
|
100
100
|
});
|
|
101
101
|
}
|
|
102
|
+
extendPages((pages) => {
|
|
103
|
+
pages.push({
|
|
104
|
+
name: "cobras-auth-error",
|
|
105
|
+
path: "/_auth/error",
|
|
106
|
+
file: resolver.resolve("./runtime/pages/auth-error.vue")
|
|
107
|
+
});
|
|
108
|
+
});
|
|
102
109
|
if (options.debug) {
|
|
103
110
|
console.log("[@cobras/auth-nuxt] Module configured:", {
|
|
104
111
|
mode: options.mode,
|
|
@@ -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;
|
|
@@ -6,10 +6,17 @@ export default defineNuxtRouteMiddleware(async (to) => {
|
|
|
6
6
|
if (to.query.code) {
|
|
7
7
|
return;
|
|
8
8
|
}
|
|
9
|
-
if (
|
|
9
|
+
if (authConfig.mode === "public") {
|
|
10
10
|
return;
|
|
11
11
|
}
|
|
12
|
-
if (
|
|
12
|
+
if (!state.value?.initialized) {
|
|
13
|
+
if (typeof window === "undefined") {
|
|
14
|
+
const requestUrl = useRequestURL();
|
|
15
|
+
return navigateTo(
|
|
16
|
+
`${authConfig.authServiceUrl}/api/auth/authorize?redirect_uri=${encodeURIComponent(requestUrl.href)}`,
|
|
17
|
+
{ external: true }
|
|
18
|
+
);
|
|
19
|
+
}
|
|
13
20
|
return;
|
|
14
21
|
}
|
|
15
22
|
const isPublicRoute = authConfig.publicRoutes.some((route) => {
|
|
@@ -26,7 +33,8 @@ export default defineNuxtRouteMiddleware(async (to) => {
|
|
|
26
33
|
if (typeof window !== "undefined") {
|
|
27
34
|
redirectUrl = window.location.href;
|
|
28
35
|
} else {
|
|
29
|
-
|
|
36
|
+
const requestUrl = useRequestURL();
|
|
37
|
+
redirectUrl = requestUrl.href;
|
|
30
38
|
}
|
|
31
39
|
return navigateTo(
|
|
32
40
|
`${authConfig.authServiceUrl}/api/auth/authorize?redirect_uri=${encodeURIComponent(redirectUrl)}`,
|
|
@@ -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;
|
|
@@ -7,10 +7,23 @@ export default defineNuxtRouteMiddleware(async (to) => {
|
|
|
7
7
|
return;
|
|
8
8
|
}
|
|
9
9
|
if (!state.value?.initialized) {
|
|
10
|
+
if (typeof window === "undefined") {
|
|
11
|
+
const requestUrl = useRequestURL();
|
|
12
|
+
return navigateTo(
|
|
13
|
+
`${authConfig.authServiceUrl}/api/auth/authorize?redirect_uri=${encodeURIComponent(requestUrl.href)}`,
|
|
14
|
+
{ external: true }
|
|
15
|
+
);
|
|
16
|
+
}
|
|
10
17
|
return;
|
|
11
18
|
}
|
|
12
19
|
if (!state.value?.user) {
|
|
13
|
-
|
|
20
|
+
let currentUrl;
|
|
21
|
+
if (typeof window !== "undefined") {
|
|
22
|
+
currentUrl = window.location.href;
|
|
23
|
+
} else {
|
|
24
|
+
const requestUrl = useRequestURL();
|
|
25
|
+
currentUrl = requestUrl.href;
|
|
26
|
+
}
|
|
14
27
|
return navigateTo(
|
|
15
28
|
`${authConfig.authServiceUrl}/api/auth/authorize?redirect_uri=${encodeURIComponent(currentUrl)}`,
|
|
16
29
|
{ external: true }
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { useRoute, useRuntimeConfig } from '#imports'
|
|
3
|
+
|
|
4
|
+
const route = useRoute()
|
|
5
|
+
const config = useRuntimeConfig()
|
|
6
|
+
const authConfig = config.public.cobrasAuth
|
|
7
|
+
|
|
8
|
+
const error = computed(() => route.query.error as string || 'Authentication Failed')
|
|
9
|
+
const message = computed(() => route.query.message as string || 'Unable to authenticate. Please try again.')
|
|
10
|
+
const redirectUri = computed(() => route.query.redirect_uri as string)
|
|
11
|
+
|
|
12
|
+
function retry() {
|
|
13
|
+
if (redirectUri.value) {
|
|
14
|
+
window.location.href = `${authConfig.authServiceUrl}/api/auth/authorize?redirect_uri=${encodeURIComponent(redirectUri.value)}`
|
|
15
|
+
} else {
|
|
16
|
+
window.location.href = '/'
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
</script>
|
|
20
|
+
|
|
21
|
+
<template>
|
|
22
|
+
<div class="cobras-auth-error">
|
|
23
|
+
<div class="error-card">
|
|
24
|
+
<div class="error-icon">
|
|
25
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="64" height="64" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round">
|
|
26
|
+
<circle cx="12" cy="12" r="10"></circle>
|
|
27
|
+
<line x1="12" y1="8" x2="12" y2="12"></line>
|
|
28
|
+
<line x1="12" y1="16" x2="12.01" y2="16"></line>
|
|
29
|
+
</svg>
|
|
30
|
+
</div>
|
|
31
|
+
|
|
32
|
+
<h1>{{ error }}</h1>
|
|
33
|
+
<p>{{ message }}</p>
|
|
34
|
+
|
|
35
|
+
<div class="actions">
|
|
36
|
+
<button class="btn-primary" @click="retry">
|
|
37
|
+
Try Again
|
|
38
|
+
</button>
|
|
39
|
+
<a href="/" class="btn-secondary">
|
|
40
|
+
Go Home
|
|
41
|
+
</a>
|
|
42
|
+
</div>
|
|
43
|
+
|
|
44
|
+
<p class="footer">
|
|
45
|
+
If this problem persists, contact your administrator.
|
|
46
|
+
</p>
|
|
47
|
+
</div>
|
|
48
|
+
</div>
|
|
49
|
+
</template>
|
|
50
|
+
|
|
51
|
+
<style scoped>
|
|
52
|
+
.cobras-auth-error{align-items:center;background:linear-gradient(135deg,#1a1a2e,#16213e);display:flex;font-family:system-ui,-apple-system,sans-serif;justify-content:center;min-height:100vh;padding:20px}.error-card{background:#fff;border-radius:16px;box-shadow:0 8px 32px rgba(0,0,0,.2);max-width:420px;padding:48px 40px;text-align:center;width:100%}.error-icon{color:#dc3545;margin-bottom:24px}h1{color:#1a1a2e;font-size:24px;font-weight:600;margin:0 0 12px}p{color:#666;font-size:15px;line-height:1.6;margin:0 0 32px}.actions{display:flex;flex-direction:column;gap:12px}.btn-primary{background:#1976d2;border:none;border-radius:8px;color:#fff;cursor:pointer;display:block;font-size:16px;font-weight:600;padding:14px 24px;transition:background .2s;width:100%}.btn-primary:hover{background:#1565c0}.btn-secondary{background:#f5f5f5;border:none;border-radius:8px;color:#666;cursor:pointer;display:block;font-size:16px;font-weight:500;padding:14px 24px;text-decoration:none;transition:background .2s;width:100%}.btn-secondary:hover{background:#e8e8e8}.footer{border-top:1px solid #eee;color:#999;font-size:13px;margin-top:24px;padding-top:24px}
|
|
53
|
+
</style>
|
|
@@ -83,6 +83,16 @@ export default defineNuxtPlugin(async (nuxtApp) => {
|
|
|
83
83
|
const newQuery = { ...route.query };
|
|
84
84
|
delete newQuery.code;
|
|
85
85
|
router.replace({ query: newQuery });
|
|
86
|
+
} else {
|
|
87
|
+
const currentUrl = window.location.origin + window.location.pathname;
|
|
88
|
+
router.replace({
|
|
89
|
+
path: "/_auth/error",
|
|
90
|
+
query: {
|
|
91
|
+
error: "Authentication Failed",
|
|
92
|
+
message: "Unable to complete login. The authorization code may have expired.",
|
|
93
|
+
redirect_uri: currentUrl
|
|
94
|
+
}
|
|
95
|
+
});
|
|
86
96
|
}
|
|
87
97
|
}
|
|
88
98
|
await checkAuth();
|