@hellocoop/nextjs 2.9.4 → 2.10.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/app.d.ts +12 -0
- package/dist/app.d.ts.map +1 -0
- package/dist/app.js +82 -0
- package/dist/auth.d.ts +1 -13
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +15 -66
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -15
- package/dist/pages.d.ts +15 -0
- package/dist/pages.d.ts.map +1 -0
- package/dist/pages.js +73 -0
- package/package.json +1 -1
package/dist/app.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { NextRequest, NextResponse } from 'next/server';
|
|
2
|
+
import { Auth } from '@hellocoop/types';
|
|
3
|
+
import { Config } from '@hellocoop/router';
|
|
4
|
+
declare module 'next/server' {
|
|
5
|
+
interface NextRequest {
|
|
6
|
+
auth?: Auth;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
type HandlerFunction = (req: NextRequest) => Promise<NextResponse>;
|
|
10
|
+
export declare const appAuth: (config: Config) => HandlerFunction;
|
|
11
|
+
export {};
|
|
12
|
+
//# sourceMappingURL=app.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAExD,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAA;AAEvC,OAAO,EAOH,MAAM,EACT,MAAM,mBAAmB,CAAA;AAE1B,OAAO,QAAQ,aAAa,CAAC;IACzB,UAAU,WAAW;QACjB,IAAI,CAAC,EAAE,IAAI,CAAC;KACf;CACJ;AA0DD,KAAK,eAAe,GAAG,CAAC,GAAG,EAAE,WAAW,KAAK,OAAO,CAAC,YAAY,CAAC,CAAC;AAGnE,eAAO,MAAM,OAAO,WAAa,MAAM,KAAG,eA0BzC,CAAA"}
|
package/dist/app.js
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// app router
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.appAuth = void 0;
|
|
5
|
+
const cookie_1 = require("cookie");
|
|
6
|
+
const server_1 = require("next/server");
|
|
7
|
+
const router_1 = require("@hellocoop/router");
|
|
8
|
+
function headersToObject(headers) {
|
|
9
|
+
const object = {};
|
|
10
|
+
headers.forEach((value, key) => {
|
|
11
|
+
object[key] = value;
|
|
12
|
+
});
|
|
13
|
+
return object;
|
|
14
|
+
}
|
|
15
|
+
function urlSearchParamsToObject(params) {
|
|
16
|
+
const obj = {};
|
|
17
|
+
params.forEach((value, key) => {
|
|
18
|
+
obj[key] = value;
|
|
19
|
+
});
|
|
20
|
+
return obj;
|
|
21
|
+
}
|
|
22
|
+
const convertToHelloRequest = (req) => {
|
|
23
|
+
return {
|
|
24
|
+
headers: () => { return headersToObject(req.headers); },
|
|
25
|
+
query: urlSearchParamsToObject(req.nextUrl.searchParams),
|
|
26
|
+
path: req.nextUrl.pathname,
|
|
27
|
+
getAuth: () => req.auth,
|
|
28
|
+
setAuth: (auth) => { req.auth = auth; },
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
const convertToHelloResponse = (res) => {
|
|
32
|
+
return {
|
|
33
|
+
clearAuth: () => {
|
|
34
|
+
const { name, value, options } = (0, router_1.clearAuthCookieParams)();
|
|
35
|
+
res.headers.append('Set-Cookie', (0, cookie_1.serialize)(name, value, options));
|
|
36
|
+
},
|
|
37
|
+
send: (data) => {
|
|
38
|
+
res.body = data;
|
|
39
|
+
res.headers.set('Content-Type', 'text/html');
|
|
40
|
+
},
|
|
41
|
+
json: (json) => res.json = json,
|
|
42
|
+
redirect: (url) => res.redirect = url,
|
|
43
|
+
setCookie: (name, value, options) => {
|
|
44
|
+
res.headers.append('Set-Cookie', (0, cookie_1.serialize)(name, value, options));
|
|
45
|
+
},
|
|
46
|
+
setHeader: (name, value) => res.headers.set(name, value),
|
|
47
|
+
status: (statusCode) => {
|
|
48
|
+
res.status = statusCode;
|
|
49
|
+
return {
|
|
50
|
+
send: (data) => {
|
|
51
|
+
res.body = data;
|
|
52
|
+
res.headers.set('Content-Type', 'text/html');
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
const appAuth = (config) => {
|
|
59
|
+
if (!router_1.isConfigured) {
|
|
60
|
+
(0, router_1.configure)(config);
|
|
61
|
+
}
|
|
62
|
+
const r = async (req) => {
|
|
63
|
+
const internalResponse = {
|
|
64
|
+
status: 200,
|
|
65
|
+
headers: new Headers(),
|
|
66
|
+
};
|
|
67
|
+
const helloReq = convertToHelloRequest(req);
|
|
68
|
+
const helloRes = convertToHelloResponse(internalResponse);
|
|
69
|
+
await (0, router_1.router)(helloReq, helloRes);
|
|
70
|
+
if (internalResponse.redirect)
|
|
71
|
+
return server_1.NextResponse.redirect(new URL(internalResponse.redirect, req.url), { headers: internalResponse.headers });
|
|
72
|
+
if (internalResponse.json)
|
|
73
|
+
return server_1.NextResponse.json(internalResponse.json, { headers: internalResponse.headers });
|
|
74
|
+
const res = new server_1.NextResponse(internalResponse.body, {
|
|
75
|
+
status: internalResponse.status,
|
|
76
|
+
headers: internalResponse.headers
|
|
77
|
+
});
|
|
78
|
+
return res;
|
|
79
|
+
};
|
|
80
|
+
return r;
|
|
81
|
+
};
|
|
82
|
+
exports.appAuth = appAuth;
|
package/dist/auth.d.ts
CHANGED
|
@@ -1,15 +1,3 @@
|
|
|
1
|
-
import type { GetServerSidePropsContext, GetServerSidePropsResult, NextApiHandler, NextApiRequest } from 'next';
|
|
2
1
|
import { Auth } from '@hellocoop/types';
|
|
3
|
-
|
|
4
|
-
export type HelloConfig = Config;
|
|
5
|
-
declare module 'next' {
|
|
6
|
-
interface NextApiRequest {
|
|
7
|
-
auth?: Auth;
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
export declare const getServerSideProps: (context: GetServerSidePropsContext) => Promise<GetServerSidePropsResult<{
|
|
11
|
-
auth: Auth;
|
|
12
|
-
}>>;
|
|
13
|
-
export declare const getAuth: (req: NextApiRequest) => Promise<Auth>;
|
|
14
|
-
export declare const pageAuth: (config: Config) => NextApiHandler;
|
|
2
|
+
export declare const auth: () => Promise<Auth>;
|
|
15
3
|
//# sourceMappingURL=auth.d.ts.map
|
package/dist/auth.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAA;AAMvC,eAAO,MAAM,IAAI,QAAsB,QAAQ,IAAI,CAelD,CAAA"}
|
package/dist/auth.js
CHANGED
|
@@ -1,71 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const cookie_1 = require("cookie");
|
|
3
|
+
exports.auth = void 0;
|
|
5
4
|
const router_1 = require("@hellocoop/router");
|
|
6
|
-
const
|
|
7
|
-
const
|
|
5
|
+
const headers_1 = require("next/headers");
|
|
6
|
+
const core_1 = require("@hellocoop/core");
|
|
7
|
+
const constants_1 = require("@hellocoop/constants");
|
|
8
|
+
const auth = async function () {
|
|
8
9
|
var _a;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
const authCookie = (_a = (0, headers_1.cookies)().get(router_1.configuration.cookies.authName)) === null || _a === void 0 ? void 0 : _a.value;
|
|
11
|
+
console.log({ authCookie });
|
|
12
|
+
if (!authCookie)
|
|
13
|
+
return constants_1.NotLoggedIn;
|
|
14
|
+
const a = await (0, core_1.decryptObj)(authCookie, router_1.configuration.secret);
|
|
15
|
+
console.log({ a });
|
|
16
|
+
if (!a)
|
|
17
|
+
return constants_1.NotLoggedIn;
|
|
18
|
+
return a;
|
|
16
19
|
};
|
|
17
|
-
|
|
18
|
-
return {
|
|
19
|
-
clearAuth: () => {
|
|
20
|
-
const { name, value, options } = (0, router_1.clearAuthCookieParams)();
|
|
21
|
-
res.setHeader('Set-Cookie', (0, cookie_1.serialize)(name, value, options));
|
|
22
|
-
},
|
|
23
|
-
send: (data) => res.send(data),
|
|
24
|
-
json: (data) => res.json(data),
|
|
25
|
-
redirect: (url) => res.redirect(url),
|
|
26
|
-
setCookie: (name, value, options) => {
|
|
27
|
-
res.setHeader('Set-Cookie', (0, cookie_1.serialize)(name, value, options));
|
|
28
|
-
},
|
|
29
|
-
setHeader: (name, value) => res.setHeader(name, value),
|
|
30
|
-
status: (statusCode) => {
|
|
31
|
-
res.status(statusCode);
|
|
32
|
-
return {
|
|
33
|
-
send: (data) => res.send(data)
|
|
34
|
-
};
|
|
35
|
-
},
|
|
36
|
-
};
|
|
37
|
-
};
|
|
38
|
-
const getServerSideProps = async function (context) {
|
|
39
|
-
const req = context.req;
|
|
40
|
-
if (req.auth)
|
|
41
|
-
return {
|
|
42
|
-
props: { auth: req.auth }
|
|
43
|
-
};
|
|
44
|
-
const helloReq = convertToHelloRequest(req);
|
|
45
|
-
const helloRes = convertToHelloResponse(context.res);
|
|
46
|
-
const auth = await (0, router_1.getAuthfromCookies)(helloReq, helloRes);
|
|
47
|
-
return {
|
|
48
|
-
props: { auth }
|
|
49
|
-
};
|
|
50
|
-
};
|
|
51
|
-
exports.getServerSideProps = getServerSideProps;
|
|
52
|
-
const getAuth = async function (req) {
|
|
53
|
-
if (req.auth)
|
|
54
|
-
return req.auth;
|
|
55
|
-
const helloReq = convertToHelloRequest(req);
|
|
56
|
-
const auth = await (0, router_1.getAuthfromCookies)(helloReq);
|
|
57
|
-
return auth;
|
|
58
|
-
};
|
|
59
|
-
exports.getAuth = getAuth;
|
|
60
|
-
const pageAuth = function (config) {
|
|
61
|
-
if (!router_1.isConfigured) {
|
|
62
|
-
(0, router_1.configure)(config);
|
|
63
|
-
}
|
|
64
|
-
const r = async (req, res) => {
|
|
65
|
-
const helloReq = convertToHelloRequest(req);
|
|
66
|
-
const helloRes = convertToHelloResponse(res);
|
|
67
|
-
await (0, router_1.router)(helloReq, helloRes);
|
|
68
|
-
};
|
|
69
|
-
return r;
|
|
70
|
-
};
|
|
71
|
-
exports.pageAuth = pageAuth;
|
|
20
|
+
exports.auth = auth;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
export
|
|
2
|
-
export { LoggedInParams, LoggedInResponse, CallbackRequest, CallbackResponse } from '@hellocoop/router';
|
|
1
|
+
export type { Config as HelloConfig, LoggedInParams, LoggedInResponse, CallbackRequest, CallbackResponse } from '@hellocoop/router';
|
|
3
2
|
export type { Auth } from '@hellocoop/types';
|
|
3
|
+
export { getAuth, getServerSideProps, pageAuth, pagesAuth } from './pages';
|
|
4
|
+
export { appAuth } from './app';
|
|
5
|
+
export { auth } from './auth';
|
|
4
6
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACR,MAAM,IAAI,WAAW,EACrB,cAAc,EACd,gBAAgB,EAChB,eAAe,EACf,gBAAgB,EACnB,MAAM,mBAAmB,CAAA;AAC1B,YAAY,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAA;AAG5C,OAAO,EAAE,OAAO,EAAE,kBAAkB,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAE1E,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AAC/B,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,17 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
|
|
3
|
+
exports.auth = exports.appAuth = exports.pagesAuth = exports.pageAuth = exports.getServerSideProps = exports.getAuth = void 0;
|
|
4
|
+
// pageAuth is synonym for pagesAuth
|
|
5
|
+
var pages_1 = require("./pages");
|
|
6
|
+
Object.defineProperty(exports, "getAuth", { enumerable: true, get: function () { return pages_1.getAuth; } });
|
|
7
|
+
Object.defineProperty(exports, "getServerSideProps", { enumerable: true, get: function () { return pages_1.getServerSideProps; } });
|
|
8
|
+
Object.defineProperty(exports, "pageAuth", { enumerable: true, get: function () { return pages_1.pageAuth; } });
|
|
9
|
+
Object.defineProperty(exports, "pagesAuth", { enumerable: true, get: function () { return pages_1.pagesAuth; } });
|
|
10
|
+
// app router functions
|
|
11
|
+
var app_1 = require("./app");
|
|
12
|
+
Object.defineProperty(exports, "appAuth", { enumerable: true, get: function () { return app_1.appAuth; } });
|
|
13
|
+
var auth_1 = require("./auth");
|
|
14
|
+
Object.defineProperty(exports, "auth", { enumerable: true, get: function () { return auth_1.auth; } });
|
package/dist/pages.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { GetServerSidePropsContext, GetServerSidePropsResult, NextApiHandler, NextApiRequest } from 'next';
|
|
2
|
+
import { Auth } from '@hellocoop/types';
|
|
3
|
+
import { Config } from '@hellocoop/router';
|
|
4
|
+
declare module 'next' {
|
|
5
|
+
interface NextApiRequest {
|
|
6
|
+
auth?: Auth;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
export declare const getServerSideProps: (context: GetServerSidePropsContext) => Promise<GetServerSidePropsResult<{
|
|
10
|
+
auth: Auth;
|
|
11
|
+
}>>;
|
|
12
|
+
export declare const getAuth: (req: NextApiRequest) => Promise<Auth>;
|
|
13
|
+
export declare const pageAuth: (config: Config) => NextApiHandler;
|
|
14
|
+
export declare const pagesAuth: (config: Config) => NextApiHandler;
|
|
15
|
+
//# sourceMappingURL=pages.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pages.d.ts","sourceRoot":"","sources":["../src/pages.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACR,yBAAyB,EACzB,wBAAwB,EACxB,cAAc,EACd,cAAc,EAEjB,MAAM,MAAM,CAAA;AAEb,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAA;AAEvC,OAAO,EAQH,MAAM,EACT,MAAM,mBAAmB,CAAA;AAI1B,OAAO,QAAQ,MAAM,CAAC;IAClB,UAAU,cAAc;QACpB,IAAI,CAAC,EAAE,IAAI,CAAC;KACf;CACJ;AAoCD,eAAO,MAAM,kBAAkB,YAA2B,yBAAyB;UACnC,IAAI;GAanD,CAAA;AAED,eAAO,MAAM,OAAO,QAAyB,cAAc,KAAG,QAAQ,IAAI,CAMzE,CAAA;AAED,eAAO,MAAM,QAAQ,WAAsB,MAAM,KAAG,cAUnD,CAAA;AAED,eAAO,MAAM,SAAS,WAZqB,MAAM,KAAG,cAYnB,CAAA"}
|
package/dist/pages.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// pages router
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.pagesAuth = exports.pageAuth = exports.getAuth = exports.getServerSideProps = void 0;
|
|
5
|
+
const cookie_1 = require("cookie");
|
|
6
|
+
const router_1 = require("@hellocoop/router");
|
|
7
|
+
const url_1 = require("url");
|
|
8
|
+
const convertToHelloRequest = (req) => {
|
|
9
|
+
var _a;
|
|
10
|
+
return {
|
|
11
|
+
headers: () => req.headers,
|
|
12
|
+
query: req.query,
|
|
13
|
+
path: req.url ? (_a = (0, url_1.parse)(req.url, true)) === null || _a === void 0 ? void 0 : _a.pathname : '/',
|
|
14
|
+
getAuth: () => req.auth,
|
|
15
|
+
setAuth: (auth) => { req.auth = auth; },
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
const convertToHelloResponse = (res) => {
|
|
19
|
+
return {
|
|
20
|
+
clearAuth: () => {
|
|
21
|
+
const { name, value, options } = (0, router_1.clearAuthCookieParams)();
|
|
22
|
+
res.setHeader('Set-Cookie', (0, cookie_1.serialize)(name, value, options));
|
|
23
|
+
},
|
|
24
|
+
send: (data) => res.send(data),
|
|
25
|
+
json: (data) => res.json(data),
|
|
26
|
+
redirect: (url) => res.redirect(url),
|
|
27
|
+
setCookie: (name, value, options) => {
|
|
28
|
+
res.setHeader('Set-Cookie', (0, cookie_1.serialize)(name, value, options));
|
|
29
|
+
},
|
|
30
|
+
setHeader: (name, value) => res.setHeader(name, value),
|
|
31
|
+
status: (statusCode) => {
|
|
32
|
+
res.status(statusCode);
|
|
33
|
+
return {
|
|
34
|
+
send: (data) => res.send(data)
|
|
35
|
+
};
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
const getServerSideProps = async function (context) {
|
|
40
|
+
const req = context.req;
|
|
41
|
+
if (req.auth)
|
|
42
|
+
return {
|
|
43
|
+
props: { auth: req.auth }
|
|
44
|
+
};
|
|
45
|
+
const helloReq = convertToHelloRequest(req);
|
|
46
|
+
const helloRes = convertToHelloResponse(context.res);
|
|
47
|
+
const auth = await (0, router_1.getAuthfromCookies)(helloReq, helloRes);
|
|
48
|
+
return {
|
|
49
|
+
props: { auth }
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
exports.getServerSideProps = getServerSideProps;
|
|
53
|
+
const getAuth = async function (req) {
|
|
54
|
+
if (req.auth)
|
|
55
|
+
return req.auth;
|
|
56
|
+
const helloReq = convertToHelloRequest(req);
|
|
57
|
+
const auth = await (0, router_1.getAuthfromCookies)(helloReq);
|
|
58
|
+
return auth;
|
|
59
|
+
};
|
|
60
|
+
exports.getAuth = getAuth;
|
|
61
|
+
const pageAuth = function (config) {
|
|
62
|
+
if (!router_1.isConfigured) {
|
|
63
|
+
(0, router_1.configure)(config);
|
|
64
|
+
}
|
|
65
|
+
const r = async (req, res) => {
|
|
66
|
+
const helloReq = convertToHelloRequest(req);
|
|
67
|
+
const helloRes = convertToHelloResponse(res);
|
|
68
|
+
await (0, router_1.router)(helloReq, helloRes);
|
|
69
|
+
};
|
|
70
|
+
return r;
|
|
71
|
+
};
|
|
72
|
+
exports.pageAuth = pageAuth;
|
|
73
|
+
exports.pagesAuth = exports.pageAuth;
|