@frequencyads/auth 0.1.0
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/chunk-JIENWB3K.mjs +89 -0
- package/dist/chunk-NS2JRZGO.mjs +38 -0
- package/dist/chunk-OKP757OV.mjs +131 -0
- package/dist/chunk-OUUVIDG6.mjs +63 -0
- package/dist/chunk-P4OKC4U7.mjs +41 -0
- package/dist/chunk-VBLFQXCD.mjs +406 -0
- package/dist/chunk-VQCPN62H.mjs +134 -0
- package/dist/chunk-XJFMS3SM.mjs +21 -0
- package/dist/components/auth-provider.d.mts +24 -0
- package/dist/components/auth-provider.d.ts +24 -0
- package/dist/components/auth-provider.js +107 -0
- package/dist/components/auth-provider.mjs +11 -0
- package/dist/components/login.d.mts +24 -0
- package/dist/components/login.d.ts +24 -0
- package/dist/components/login.js +430 -0
- package/dist/components/login.mjs +9 -0
- package/dist/components/reset-password.d.mts +11 -0
- package/dist/components/reset-password.d.ts +11 -0
- package/dist/components/reset-password.js +283 -0
- package/dist/components/reset-password.mjs +10 -0
- package/dist/components/sign-out-button.d.mts +11 -0
- package/dist/components/sign-out-button.d.ts +11 -0
- package/dist/components/sign-out-button.js +90 -0
- package/dist/components/sign-out-button.mjs +11 -0
- package/dist/components/user-menu.d.mts +5 -0
- package/dist/components/user-menu.d.ts +5 -0
- package/dist/components/user-menu.js +107 -0
- package/dist/components/user-menu.mjs +11 -0
- package/dist/components/verify-code.d.mts +20 -0
- package/dist/components/verify-code.d.ts +20 -0
- package/dist/components/verify-code.js +155 -0
- package/dist/components/verify-code.mjs +9 -0
- package/dist/index.d.mts +44 -0
- package/dist/index.d.ts +44 -0
- package/dist/index.js +1006 -0
- package/dist/index.mjs +159 -0
- package/dist/middleware.d.mts +29 -0
- package/dist/middleware.d.ts +29 -0
- package/dist/middleware.js +114 -0
- package/dist/middleware.mjs +83 -0
- package/dist/proxy.d.mts +9 -0
- package/dist/proxy.d.ts +9 -0
- package/dist/proxy.js +71 -0
- package/dist/proxy.mjs +41 -0
- package/dist/request.d.mts +14 -0
- package/dist/request.d.ts +14 -0
- package/dist/request.js +46 -0
- package/dist/request.mjs +8 -0
- package/package.json +101 -0
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
"use strict";
|
|
3
|
+
"use client";
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
21
|
+
|
|
22
|
+
// src/components/verify-code.tsx
|
|
23
|
+
var verify_code_exports = {};
|
|
24
|
+
__export(verify_code_exports, {
|
|
25
|
+
VerifyCodeForm: () => VerifyCodeForm
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(verify_code_exports);
|
|
28
|
+
var import_react = require("react");
|
|
29
|
+
var import_core = require("@mantine/core");
|
|
30
|
+
var import_client = require("@frequencyads/db/client");
|
|
31
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
32
|
+
function VerifyCodeForm({
|
|
33
|
+
email,
|
|
34
|
+
type,
|
|
35
|
+
onSuccess,
|
|
36
|
+
onResend,
|
|
37
|
+
onBack,
|
|
38
|
+
backLabel = "Back to sign in",
|
|
39
|
+
header
|
|
40
|
+
}) {
|
|
41
|
+
const [code, setCode] = (0, import_react.useState)("");
|
|
42
|
+
const [error, setError] = (0, import_react.useState)(null);
|
|
43
|
+
const [loading, setLoading] = (0, import_react.useState)(false);
|
|
44
|
+
const [verified, setVerified] = (0, import_react.useState)(false);
|
|
45
|
+
const [resendCooldown, setResendCooldown] = (0, import_react.useState)(0);
|
|
46
|
+
(0, import_react.useEffect)(() => {
|
|
47
|
+
if (resendCooldown <= 0) return;
|
|
48
|
+
const timer = setTimeout(() => setResendCooldown((c) => c - 1), 1e3);
|
|
49
|
+
return () => clearTimeout(timer);
|
|
50
|
+
}, [resendCooldown]);
|
|
51
|
+
const handleVerify = (0, import_react.useCallback)(
|
|
52
|
+
async (value) => {
|
|
53
|
+
if (value.length !== 6) return;
|
|
54
|
+
setError(null);
|
|
55
|
+
setLoading(true);
|
|
56
|
+
try {
|
|
57
|
+
const supabase = (0, import_client.createBrowserClient)();
|
|
58
|
+
const { error: verifyError } = await supabase.auth.verifyOtp({
|
|
59
|
+
email,
|
|
60
|
+
token: value,
|
|
61
|
+
type
|
|
62
|
+
});
|
|
63
|
+
if (verifyError) {
|
|
64
|
+
setError("This code is invalid or has expired. Please request a new one.");
|
|
65
|
+
setCode("");
|
|
66
|
+
} else {
|
|
67
|
+
setVerified(true);
|
|
68
|
+
onSuccess();
|
|
69
|
+
}
|
|
70
|
+
} finally {
|
|
71
|
+
setLoading(false);
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
[email, type, onSuccess]
|
|
75
|
+
);
|
|
76
|
+
const [resending, setResending] = (0, import_react.useState)(false);
|
|
77
|
+
const handleResend = async () => {
|
|
78
|
+
setError(null);
|
|
79
|
+
setResending(true);
|
|
80
|
+
try {
|
|
81
|
+
const result = await onResend();
|
|
82
|
+
if (result.error) {
|
|
83
|
+
setError(result.error);
|
|
84
|
+
} else {
|
|
85
|
+
setResendCooldown(60);
|
|
86
|
+
}
|
|
87
|
+
} finally {
|
|
88
|
+
setResending(false);
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_core.Box, { w: "100%", maw: 460, children: [
|
|
92
|
+
header && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core.Box, { mb: "lg", style: { textAlign: "center" }, children: header }),
|
|
93
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core.Title, { order: 3, fw: 600, mb: "xs", c: "gray.7", children: type === "email" ? "Verify your email" : "Enter reset code" }),
|
|
94
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_core.Text, { size: "sm", c: "gray.6", mb: "lg", children: [
|
|
95
|
+
"We sent a 6-digit code to ",
|
|
96
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("strong", { children: email })
|
|
97
|
+
] }),
|
|
98
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_core.Stack, { children: [
|
|
99
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
100
|
+
import_core.PinInput,
|
|
101
|
+
{
|
|
102
|
+
length: 6,
|
|
103
|
+
type: "number",
|
|
104
|
+
oneTimeCode: true,
|
|
105
|
+
autoFocus: true,
|
|
106
|
+
size: "lg",
|
|
107
|
+
value: code,
|
|
108
|
+
onChange: (value) => {
|
|
109
|
+
setCode(value);
|
|
110
|
+
if (value.length > 0) setError(null);
|
|
111
|
+
},
|
|
112
|
+
onComplete: handleVerify,
|
|
113
|
+
error: !!error,
|
|
114
|
+
disabled: loading || verified,
|
|
115
|
+
styles: { input: { fontWeight: 600, fontSize: 20 } }
|
|
116
|
+
}
|
|
117
|
+
),
|
|
118
|
+
error && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core.Text, { size: "sm", c: "red", children: error }),
|
|
119
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
120
|
+
import_core.Button,
|
|
121
|
+
{
|
|
122
|
+
fullWidth: true,
|
|
123
|
+
size: "md",
|
|
124
|
+
loading: loading || verified,
|
|
125
|
+
onClick: () => handleVerify(code),
|
|
126
|
+
children: "Verify"
|
|
127
|
+
}
|
|
128
|
+
),
|
|
129
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_core.Text, { size: "sm", c: "gray.6", ta: "center", children: [
|
|
130
|
+
"Didn't receive the code?",
|
|
131
|
+
" ",
|
|
132
|
+
resendCooldown > 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_core.Text, { span: true, c: "gray.5", children: [
|
|
133
|
+
"Resend in ",
|
|
134
|
+
resendCooldown,
|
|
135
|
+
"s"
|
|
136
|
+
] }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
137
|
+
import_core.Anchor,
|
|
138
|
+
{
|
|
139
|
+
component: "button",
|
|
140
|
+
type: "button",
|
|
141
|
+
size: "sm",
|
|
142
|
+
onClick: handleResend,
|
|
143
|
+
disabled: resending,
|
|
144
|
+
children: resending ? "Sending\u2026" : "Resend code"
|
|
145
|
+
}
|
|
146
|
+
)
|
|
147
|
+
] }),
|
|
148
|
+
onBack && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core.Anchor, { component: "button", type: "button", size: "sm", onClick: onBack, ta: "center", children: backLabel })
|
|
149
|
+
] })
|
|
150
|
+
] });
|
|
151
|
+
}
|
|
152
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
153
|
+
0 && (module.exports = {
|
|
154
|
+
VerifyCodeForm
|
|
155
|
+
});
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import * as _supabase_supabase_js from '@supabase/supabase-js';
|
|
2
|
+
import { NextRequest, NextResponse } from 'next/server';
|
|
3
|
+
export { AuthProvider, AuthProviderProps, UserProfile, useAuth } from './components/auth-provider.mjs';
|
|
4
|
+
export { LoginPage } from './components/login.mjs';
|
|
5
|
+
export { SignOutButton, getSignOutUrl } from './components/sign-out-button.mjs';
|
|
6
|
+
export { UserMenu } from './components/user-menu.mjs';
|
|
7
|
+
export { VerifyCodeForm } from './components/verify-code.mjs';
|
|
8
|
+
export { ResetPasswordForm } from './components/reset-password.mjs';
|
|
9
|
+
import 'react/jsx-runtime';
|
|
10
|
+
import 'react';
|
|
11
|
+
import '@mantine/core';
|
|
12
|
+
|
|
13
|
+
declare function updateSession(request: NextRequest): Promise<{
|
|
14
|
+
supabaseResponse: NextResponse<unknown>;
|
|
15
|
+
claims: _supabase_supabase_js.JwtPayload | null;
|
|
16
|
+
}>;
|
|
17
|
+
|
|
18
|
+
type AccessLevel = 'org-member' | 'employee';
|
|
19
|
+
interface AuthMiddlewareOptions {
|
|
20
|
+
/** Required access level for this app. */
|
|
21
|
+
access: AccessLevel;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Create a Next.js middleware that gates access based on org membership or employee role.
|
|
25
|
+
*
|
|
26
|
+
* - Unauthenticated users are redirected to account.frequency.media/login
|
|
27
|
+
* - Authenticated users without the required access level are redirected to
|
|
28
|
+
* account.frequency.media with an access_denied error
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* // middleware.ts (private app — org members only)
|
|
32
|
+
* export const middleware = createAuthMiddleware({ access: 'org-member' });
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* // middleware.ts (internal app — employees only)
|
|
36
|
+
* export const middleware = createAuthMiddleware({ access: 'employee' });
|
|
37
|
+
*/
|
|
38
|
+
declare function createAuthMiddleware({ access }: AuthMiddlewareOptions): (request: NextRequest) => Promise<NextResponse<unknown>>;
|
|
39
|
+
/** Default matcher config for use in consuming apps. */
|
|
40
|
+
declare const defaultMatcher: {
|
|
41
|
+
matcher: string[];
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export { createAuthMiddleware, defaultMatcher, updateSession };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import * as _supabase_supabase_js from '@supabase/supabase-js';
|
|
2
|
+
import { NextRequest, NextResponse } from 'next/server';
|
|
3
|
+
export { AuthProvider, AuthProviderProps, UserProfile, useAuth } from './components/auth-provider.js';
|
|
4
|
+
export { LoginPage } from './components/login.js';
|
|
5
|
+
export { SignOutButton, getSignOutUrl } from './components/sign-out-button.js';
|
|
6
|
+
export { UserMenu } from './components/user-menu.js';
|
|
7
|
+
export { VerifyCodeForm } from './components/verify-code.js';
|
|
8
|
+
export { ResetPasswordForm } from './components/reset-password.js';
|
|
9
|
+
import 'react/jsx-runtime';
|
|
10
|
+
import 'react';
|
|
11
|
+
import '@mantine/core';
|
|
12
|
+
|
|
13
|
+
declare function updateSession(request: NextRequest): Promise<{
|
|
14
|
+
supabaseResponse: NextResponse<unknown>;
|
|
15
|
+
claims: _supabase_supabase_js.JwtPayload | null;
|
|
16
|
+
}>;
|
|
17
|
+
|
|
18
|
+
type AccessLevel = 'org-member' | 'employee';
|
|
19
|
+
interface AuthMiddlewareOptions {
|
|
20
|
+
/** Required access level for this app. */
|
|
21
|
+
access: AccessLevel;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Create a Next.js middleware that gates access based on org membership or employee role.
|
|
25
|
+
*
|
|
26
|
+
* - Unauthenticated users are redirected to account.frequency.media/login
|
|
27
|
+
* - Authenticated users without the required access level are redirected to
|
|
28
|
+
* account.frequency.media with an access_denied error
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* // middleware.ts (private app — org members only)
|
|
32
|
+
* export const middleware = createAuthMiddleware({ access: 'org-member' });
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* // middleware.ts (internal app — employees only)
|
|
36
|
+
* export const middleware = createAuthMiddleware({ access: 'employee' });
|
|
37
|
+
*/
|
|
38
|
+
declare function createAuthMiddleware({ access }: AuthMiddlewareOptions): (request: NextRequest) => Promise<NextResponse<unknown>>;
|
|
39
|
+
/** Default matcher config for use in consuming apps. */
|
|
40
|
+
declare const defaultMatcher: {
|
|
41
|
+
matcher: string[];
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export { createAuthMiddleware, defaultMatcher, updateSession };
|