kenny-login 0.0.2 → 0.0.4-beta.1

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.
@@ -0,0 +1,3 @@
1
+ export declare function signInWithProvider(providerId: string, callbackUrl?: string): Promise<void>;
2
+ export declare function signInWithCredentials(formData: FormData, callbackUrl?: string): Promise<void>;
3
+ //# sourceMappingURL=strapiSignInActions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"strapiSignInActions.d.ts","sourceRoot":"","sources":["../../src/actions/strapiSignInActions.ts"],"names":[],"mappings":"AAGA,wBAAsB,kBAAkB,CAAC,UAAU,EAAE,MAAM,EAAE,WAAW,SAAM,iBAE7E;AAED,wBAAsB,qBAAqB,CAAC,QAAQ,EAAE,QAAQ,EAAE,WAAW,SAAM,iBAehF"}
@@ -0,0 +1,20 @@
1
+ "use server";
2
+ import { signIn as serverSignIn } from "../strapiAuth";
3
+ export async function signInWithProvider(providerId, callbackUrl = "/") {
4
+ await serverSignIn(providerId, { redirectTo: callbackUrl });
5
+ }
6
+ export async function signInWithCredentials(formData, callbackUrl = "/") {
7
+ const email = formData.get("email");
8
+ const password = formData.get("password");
9
+ if (!email || !password) {
10
+ throw new Error("Email and password are required.");
11
+ }
12
+ await serverSignIn("credentials", {
13
+ redirectTo: callbackUrl,
14
+ credentials: {
15
+ email,
16
+ password
17
+ }
18
+ });
19
+ }
20
+ //# sourceMappingURL=strapiSignInActions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"strapiSignInActions.js","sourceRoot":"","sources":["../../src/actions/strapiSignInActions.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AACb,OAAO,EAAE,MAAM,IAAI,YAAY,EAAE,MAAM,eAAe,CAAC;AAEvD,MAAM,CAAC,KAAK,UAAU,kBAAkB,CAAC,UAAkB,EAAE,WAAW,GAAG,GAAG;IAC5E,MAAM,YAAY,CAAC,UAAU,EAAE,EAAE,UAAU,EAAE,WAAW,EAAE,CAAC,CAAC;AAC9D,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,qBAAqB,CAAC,QAAkB,EAAE,WAAW,GAAG,GAAG;IAC/E,MAAM,KAAK,GAAG,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAW,CAAC;IAC9C,MAAM,QAAQ,GAAG,QAAQ,CAAC,GAAG,CAAC,UAAU,CAAW,CAAC;IAEpD,IAAI,CAAC,KAAK,IAAI,CAAC,QAAQ,EAAE,CAAC;QACxB,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC;IACtD,CAAC;IAED,MAAM,YAAY,CAAC,aAAa,EAAE;QAChC,UAAU,EAAE,WAAW;QACvB,WAAW,EAAE;YACX,KAAK;YACL,QAAQ;SACT;KACF,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,8 @@
1
+ export declare function SignInForm(props: {
2
+ searchParams: {
3
+ callbackUrl: string | undefined;
4
+ };
5
+ auth: any;
6
+ signIn: any;
7
+ }): import("react").JSX.Element;
8
+ //# sourceMappingURL=signInForm.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signInForm.d.ts","sourceRoot":"","sources":["../../src/components/signInForm.tsx"],"names":[],"mappings":"AAMA,wBAAgB,UAAU,CACxB,KAAK,EAAE;IACL,YAAY,EAAE;QAAE,WAAW,EAAE,MAAM,GAAG,SAAS,CAAA;KAAE,CAAC;IAClD,IAAI,EAAE,GAAG,CAAC;IACV,MAAM,EAAE,GAAG,CAAC;CACb,+BA4DF"}
@@ -0,0 +1,48 @@
1
+ 'use client';
2
+ import { getProviders } from "next-auth/react";
3
+ import { signInWithProvider, signInWithCredentials } from "../actions/strapiSignInActions";
4
+ import { useEffect, useState } from "react";
5
+ export function SignInForm(props) {
6
+ const [providers, setProviders] = useState({});
7
+ useEffect(() => {
8
+ async function fetchProviders() {
9
+ const provs = await getProviders();
10
+ console.log('providers ->', provs);
11
+ if (provs) {
12
+ setProviders(provs);
13
+ }
14
+ }
15
+ fetchProviders();
16
+ }, []);
17
+ return (<div className="kl-sign-in-form--wrapper">
18
+ <form id="signInForm" name="Sign In" className="kl-sign-in-form" action={async (formData) => { signInWithCredentials(formData, props.searchParams.callbackUrl); }}>
19
+ <title>Sign in</title>
20
+ <div className="kl-sign-in-form--field">
21
+ <label htmlFor="email">
22
+ {/* {credentials.email.label} */}
23
+ Email
24
+ </label>
25
+ {/* <input name="email" id="email" type={credentials.email.type} /> */}
26
+ <input name="email" id="email"></input>
27
+ </div>
28
+ <div className="kl-sign-in-form--field">
29
+ <label htmlFor="password">
30
+ {/* {credentials.password.label} */}
31
+ Password
32
+ </label>
33
+ {/* <input name="password" id="password" type={credentials.password.type} /> */}
34
+ <input name="password" id="password"></input>
35
+ </div>
36
+ <button type="submit" className="kl-sign-in-form--submit-button">
37
+ Sign In
38
+ </button>
39
+ </form>
40
+
41
+ {Object.values(providers).map((provider) => (<form className="kl-sign-in-form--providers-list" key={provider.id} action={async () => { signInWithProvider(provider.id, props.searchParams.callbackUrl); }}>
42
+ <button type="submit" className="kl-sign-in-form--provider-button">
43
+ Sign in with {provider.name}
44
+ </button>
45
+ </form>))}
46
+ </div>);
47
+ }
48
+ //# sourceMappingURL=signInForm.jsx.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signInForm.jsx","sourceRoot":"","sources":["../../src/components/signInForm.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AAC3F,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAE5C,MAAM,UAAU,UAAU,CACxB,KAIC;IAED,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,QAAQ,CAA+B,EAAE,CAAC,CAAC;IAE7E,SAAS,CAAC,GAAG,EAAE;QACb,KAAK,UAAU,cAAc;YAC3B,MAAM,KAAK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C,gCAAgC,CAC9D;;QACF,EAAE,MAAM,CACV;MAAA,EAAE,IAAI,CAEN;;MAAA,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,CAC1C,CAAC,IAAI,CACH,SAAS,CAAC,iCAAiC,CAC3C,GAAG,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CACjB,MAAM,CAAC,CAAC,KAAK,IAAI,EAAE,GAAE,kBAAkB,CAAC,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC,YAAY,CAAC,WAAW,CAAC,CAAA,CAAA,CAAC,CAAC,CAChF;gBAAA,CAAC,MAAM,CACL,IAAI,CAAC,QAAQ,CACb,SAAS,CAAC,kCAAkC,CAE5C;+BAAa,CAAC,QAAQ,CAAC,IAAI,CAC7B;gBAAA,EAAE,MAAM,CAChB;QAAA,EAAE,IAAI,CAAC,CACR,CAAC,CACJ;IAAA,EAAE,GAAG,CAAC,CACP,CAAA;AACH,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,3 +1,5 @@
1
- export { handlers, signIn, signOut, auth } from "./auth";
2
- export { SignInForm } from "./components/signin-form";
1
+ export { handlers as strapiHandlers, signIn as strapiSignIn, signOut as strapiSignOut, auth as strapiAuth } from "./strapiAuth";
2
+ export { SignInForm } from "./components/signInForm";
3
+ export { ApiClient } from "./utils/ApiClient";
4
+ export { EnabledProviders } from "./utils/enabledProviders";
3
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,IAAI,cAAc,EAAE,MAAM,IAAI,YAAY,EAAE,OAAO,IAAI,aAAa,EAAE,IAAI,IAAI,UAAU,EAAE,MAAM,cAAc,CAAC;AAEhI,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC"}
package/dist/index.js CHANGED
@@ -1,3 +1,6 @@
1
- export { handlers, signIn, signOut, auth } from "./auth";
2
- export { SignInForm } from "./components/signin-form";
1
+ // NextAuth exports are exported as "strapi{export}" so that we can easily support additional API services
2
+ export { handlers as strapiHandlers, signIn as strapiSignIn, signOut as strapiSignOut, auth as strapiAuth } from "./strapiAuth";
3
+ export { SignInForm } from "./components/signInForm";
4
+ export { ApiClient } from "./utils/ApiClient";
5
+ export { EnabledProviders } from "./utils/enabledProviders";
3
6
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,0GAA0G;AAC1G,OAAO,EAAE,QAAQ,IAAI,cAAc,EAAE,MAAM,IAAI,YAAY,EAAE,OAAO,IAAI,aAAa,EAAE,IAAI,IAAI,UAAU,EAAE,MAAM,cAAc,CAAC;AAEhI,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC"}
@@ -1,10 +1,14 @@
1
1
  import { type NextAuthResult } from "next-auth";
2
+ export declare const providerMap: {
3
+ id: string;
4
+ name: string;
5
+ }[];
2
6
  export declare const auth: NextAuthResult["auth"];
3
7
  export declare const handlers: {
4
- POST: (req: import("next/server").NextRequest) => Promise<Response>;
5
8
  GET: (req: import("next/server").NextRequest) => Promise<Response>;
9
+ POST: (req: import("next/server").NextRequest) => Promise<Response>;
6
10
  };
7
- export declare const signIn: <P extends import("@auth/core/providers").ProviderId, R extends boolean = true>(provider?: P, options?: FormData | ({
11
+ export declare const signIn: <P extends import("next-auth/providers").ProviderId, R extends boolean = true>(provider?: P, options?: FormData | ({
8
12
  redirectTo?: string;
9
13
  redirect?: R;
10
14
  } & Record<string, any>), authorizationParams?: string[][] | Record<string, string> | string | URLSearchParams) => Promise<R extends false ? any : never>;
@@ -12,4 +16,4 @@ export declare const signOut: <R extends boolean = true>(options?: {
12
16
  redirectTo?: string;
13
17
  redirect?: R;
14
18
  }) => Promise<R extends false ? any : never>;
15
- //# sourceMappingURL=auth.d.ts.map
19
+ //# sourceMappingURL=strapiAuth.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"strapiAuth.d.ts","sourceRoot":"","sources":["../src/strapiAuth.ts"],"names":[],"mappings":"AAAA,OAAiB,EAAE,KAAK,cAAc,EAAE,MAAM,WAAW,CAAC;AA2I1D,eAAO,MAAM,WAAW;;;GASgC,CAAC;AAEzD,eAAO,MAAM,IAAI,EAAG,cAAc,CAAC,MAAM,CAAuB,CAAC;AACjE,eAAO,MAAM,QAAQ;;;CAA0B,CAAC;AAChD,eAAO,MAAM,MAAM;cAEgvK,CAAC;YAAyJ,CAAC;yJAFn3K,CAAC;AAC5C,eAAO,MAAM,OAAO;cAC+/M,CAAC;YAA0J,CAAC;4CADloN,CAAC"}
@@ -1,13 +1,48 @@
1
1
  import NextAuth, {} from "next-auth";
2
- import { SignInError } from "@auth/core/errors";
3
2
  import Google from "next-auth/providers/google";
4
3
  import Credentials from "next-auth/providers/credentials";
5
4
  import MicrosoftEntraID from "next-auth/providers/microsoft-entra-id";
6
- const nextAuthResult = NextAuth({
7
- providers: [
8
- Google,
9
- MicrosoftEntraID,
10
- Credentials({
5
+ import Okta from "next-auth/providers/okta";
6
+ import { SignInError } from "@auth/core/errors";
7
+ import { ApiClient } from "./utils/ApiClient";
8
+ import { EnabledProviders } from "./utils/enabledProviders";
9
+ async function refreshToken(token) {
10
+ try {
11
+ const url = new URL(`${process.env.NEXT_PUBLIC_API_URL}/api/auth/refresh`);
12
+ const response = await fetch(url, {
13
+ headers: ApiClient.defaultHeaders,
14
+ method: 'POST',
15
+ body: JSON.stringify({ refreshToken: token })
16
+ });
17
+ const refreshedToken = await response.json();
18
+ if (!response.ok) {
19
+ throw refreshedToken;
20
+ }
21
+ token.jwt = refreshedToken.jwt;
22
+ return token;
23
+ }
24
+ catch (error) {
25
+ console.log(error);
26
+ return {
27
+ ...token,
28
+ error: "RefreshAccessTokenError",
29
+ };
30
+ }
31
+ }
32
+ const getProviders = () => {
33
+ const enabledProviders = EnabledProviders();
34
+ const providers = [];
35
+ if (enabledProviders.includes("Google")) {
36
+ providers.push(Google);
37
+ }
38
+ if (enabledProviders.includes("MicrosoftEntraID")) {
39
+ providers.push(MicrosoftEntraID);
40
+ }
41
+ if (enabledProviders.includes("Okta")) {
42
+ providers.push(Okta);
43
+ }
44
+ if (enabledProviders.includes("Credentials")) {
45
+ providers.push(Credentials({
11
46
  credentials: {
12
47
  email: {
13
48
  type: "email",
@@ -21,9 +56,7 @@ const nextAuthResult = NextAuth({
21
56
  authorize: async (credentials) => {
22
57
  const response = await fetch(new URL(`${process.env.NEXT_PUBLIC_API_URL}/auth/local`), {
23
58
  method: 'POST',
24
- headers: {
25
- "Content-Type": "application/json"
26
- },
59
+ headers: ApiClient.defaultHeaders,
27
60
  body: JSON.stringify({
28
61
  identifier: credentials.email,
29
62
  password: credentials.password
@@ -36,8 +69,15 @@ const nextAuthResult = NextAuth({
36
69
  const user = { name: data.user.username, email: data.user.email, jwt: data.jwt };
37
70
  return user;
38
71
  }
39
- })
40
- ],
72
+ }));
73
+ }
74
+ return providers;
75
+ };
76
+ const nextAuthResult = NextAuth({
77
+ providers: getProviders(),
78
+ // pages: {
79
+ // signIn: "/",
80
+ // },
41
81
  session: {
42
82
  strategy: "jwt"
43
83
  },
@@ -56,17 +96,34 @@ const nextAuthResult = NextAuth({
56
96
  const response = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/auth/${strapiProviderName}/callback?access_token=${account.access_token}`);
57
97
  const data = await response.json();
58
98
  token.jwt = data.jwt;
99
+ return token;
59
100
  }
60
101
  catch (error) {
61
102
  console.error("Error in JWT callback:", error);
62
103
  }
63
104
  }
64
- return token;
105
+ // Return previous token if the access token has not expired yet
106
+ if (token.exp && Date.now() < token.exp) {
107
+ return token;
108
+ }
109
+ // Access token has expired, try to update it
110
+ return refreshToken(token);
65
111
  }
66
112
  }
67
113
  });
114
+ export const providerMap = getProviders()
115
+ .map((provider) => {
116
+ if (typeof provider === "function") {
117
+ const providerData = provider({});
118
+ return { id: providerData.id, name: providerData.name };
119
+ }
120
+ else {
121
+ return { id: provider.id, name: provider.name };
122
+ }
123
+ })
124
+ .filter((provider) => provider.id !== "credentials");
68
125
  export const auth = nextAuthResult.auth;
69
126
  export const handlers = nextAuthResult.handlers;
70
127
  export const signIn = nextAuthResult.signIn;
71
128
  export const signOut = nextAuthResult.signOut;
72
- //# sourceMappingURL=auth.js.map
129
+ //# sourceMappingURL=strapiAuth.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"strapiAuth.js","sourceRoot":"","sources":["../src/strapiAuth.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,EAAE,EAAuB,MAAM,WAAW,CAAC;AAC1D,OAAO,MAAM,MAAM,4BAA4B,CAAC;AAChD,OAAO,WAAW,MAAM,iCAAiC,CAAC;AAC1D,OAAO,gBAAgB,MAAM,wCAAwC,CAAC;AACtE,OAAO,IAAI,MAAM,0BAA0B,CAAC;A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C,GAAG,EAAE,CAAC;gBACxC,OAAO,KAAK,CAAC;YACf,CAAC;YAED,6CAA6C;YAC7C,OAAO,YAAY,CAAC,KAAK,CAAC,CAAC;QAC7B,CAAC;KACF;CACF,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,WAAW,GAAG,YAAY,EAAE;KACpC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE;IAChB,IAAI,OAAO,QAAQ,KAAK,UAAU,EAAE,CAAC;QACnC,MAAM,YAAY,GAAG,QAAQ,CAAC,EAAS,CAAC,CAAC;QACzC,OAAO,EAAE,EAAE,EAAE,YAAY,CAAC,EAAE,EAAE,IAAI,EAAE,YAAY,CAAC,IAAI,EAAE,CAAC;IAC1D,CAAC;SAAM,CAAC;QACN,OAAO,EAAE,EAAE,EAAE,QAAQ,CAAC,EAAE,EAAE,IAAI,EAAE,QAAQ,CAAC,IAAI,EAAE,CAAC;IAClD,CAAC;AACH,CAAC,CAAC;KACD,MAAM,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,EAAE,KAAK,aAAa,CAAC,CAAC;AAEzD,MAAM,CAAC,MAAM,IAAI,GAA4B,cAAc,CAAC,IAAI,CAAC;AACjE,MAAM,CAAC,MAAM,QAAQ,GAAG,cAAc,CAAC,QAAQ,CAAC;AAChD,MAAM,CAAC,MAAM,MAAM,GAAG,cAAc,CAAC,MAAM,CAAC;AAC5C,MAAM,CAAC,MAAM,OAAO,GAAG,cAAc,CAAC,OAAO,CAAC"}
@@ -0,0 +1,80 @@
1
+ export declare class ApiClient {
2
+ private apiBaseUrl;
3
+ static defaultHeaders: {
4
+ 'Content-Type': string;
5
+ };
6
+ static genericOptions: {
7
+ headers: {
8
+ 'Content-Type': string;
9
+ };
10
+ };
11
+ /**
12
+ * @param {string} apiBaseUrl - The base url of your API service. This should include any path prefixes (like "/api/", "/api/v1/", etc.)
13
+ * @param {string|null} refreshEndpoint — (Optional) The path of your jwt refresh endpoint, if it exists.
14
+ */
15
+ constructor(apiBaseUrl: string);
16
+ private getToken;
17
+ private makeRequest;
18
+ /**
19
+ * Make an arbitrary request to an endpoint that does not require authentication.
20
+ * @param {string} endpoint - The endpoint to send the request to. Should exclude your API's base url.
21
+ * @param {RequestInit} options — Request options to be passed into fetch()
22
+ */
23
+ makePublicRequest(endpoint: string, options: RequestInit): Promise<any>;
24
+ /**
25
+ * Make an arbitrary request using the logged-in user's session.
26
+ * @param {string} endpoint - The endpoint to send the request to. Should exclude your API's base url.
27
+ * @param {RequestInit} options — Request options to be passed into fetch()
28
+ */
29
+ makePrivateRequest(endpoint: string, options: RequestInit): Promise<any>;
30
+ /**
31
+ * Make a GET request to an endpoint that does not require authentication.
32
+ * @param {string} endpoint - The endpoint to send the request to. Should exclude your API's base url.
33
+ */
34
+ getPublic(endpoint: string): Promise<Object>;
35
+ /**
36
+ * Make a GET request using the logged-in user's session.
37
+ * @param {string} endpoint - The endpoint to send the request to. Should exclude your API's base url.
38
+ */
39
+ getPrivate(endpoint: string): Promise<Object>;
40
+ /**
41
+ * Make a POST request to an endpoint that does not require authentication.
42
+ * @param {string} endpoint - The endpoint to send the request to. Should exclude your API's base url.
43
+ * @param {Object} postData — The data to send with your POST request
44
+ */
45
+ postPublic(endpoint: string, postData: Object): Promise<Object>;
46
+ /**
47
+ * Make a POST request using the logged-in user's session.
48
+ * @param {string} endpoint - The endpoint to send the request to. Should exclude your API's base url.
49
+ * @param {Object} postData — The data to send with your POST request
50
+ */
51
+ postPrivate(endpoint: string, postData: Object): Promise<Object>;
52
+ /**
53
+ * Make a PUT request to an endpoint that does not require authentication.
54
+ * @param {string} endpoint - The endpoint to send the request to. Should exclude your API's base url.
55
+ * @param {Object} putData — The data to send with your PUT request
56
+ * @param {string|number|null} id — (Optional) The identifier for the resource to be updated. Will be appended to the provided endpoint path.
57
+ */
58
+ putPublic(endpoint: string, putData: Object, id?: string | number | null): Promise<Object>;
59
+ /**
60
+ * Make a PUT request using the logged-in user's session.
61
+ * @param {string} endpoint - The endpoint to send the request to. Should exclude your API's base url.
62
+ * @param {Object} putData — The data to send with your PUT request
63
+ * @param {string|number|null} id — (Optional) The identifier for the resource to be updated. Will be appended to the provided endpoint path.
64
+ */
65
+ putPrivate(endpoint: string, putData: Object, id?: string | number | null): Promise<Object>;
66
+ /**
67
+ * Make a DELETE request to an endpoint that does not require authentication.
68
+ * @param {string} endpoint - The endpoint to send the request to. Should exclude your API's base url.
69
+ * @param {string|number|null} id — (Optional) The identifier for the resource to be deleted. Will be appended to the provided endpoint path.
70
+ */
71
+ deletePublic(endpoint: string, id?: string | number | null): Promise<any>;
72
+ /**
73
+ * Make a DELETE request using the logged-in user's session.
74
+ * @param {string} endpoint - The endpoint to send the request to. Should exclude your API's base url.
75
+ * @param {string|number|null} id — (Optional) The identifier for the resource to be deleted. Will be appended to the provided endpoint path.
76
+ */
77
+ deletePrivate(endpoint: string, id?: string | number | null): Promise<any>;
78
+ private appendIdToEndpoint;
79
+ }
80
+ //# sourceMappingURL=ApiClient.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ApiClient.d.ts","sourceRoot":"","sources":["../../src/utils/ApiClient.ts"],"names":[],"mappings":"AAGA,qBAAa,SAAS;IAed,OAAO,CAAC,UAAU;IAbtB,OAAc,cAAc;;MAE3B;IAED,OAAc,cAAc;;;;MAE3B;IAED;;;MAGE;gBAEU,UAAU,EAAG,MAAM;YAGjB,QAAQ;YAWR,WAAW;IAOzB;;;;MAIE;IACW,iBAAiB,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW;IAIrE;;;;MAIE;IACW,kBAAkB,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW;IAStE;;;MAGE;IACW,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAI,OAAO,CAAC,MAAM,CAAC;IAQ1D;;;MAGE;IACW,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAI,OAAO,CAAC,MAAM,CAAC;IAQ3D;;;;MAIE;IACW,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAI,OAAO,CAAC,MAAM,CAAC;IAS7E;;;;MAIE;IACW,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAI,OAAO,CAAC,MAAM,CAAC;IAS9E;;;;;MAKE;IACW,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,GAAG,MAAM,GAAG,MAAM,GAAG,IAAW,GAAI,OAAO,CAAC,MAAM,CAAC;IAU/G;;;;;MAKE;IACW,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,GAAG,MAAM,GAAG,MAAM,GAAG,IAAW,GAAI,OAAO,CAAC,MAAM,CAAC;IAUhH;;;;MAIE;IACW,YAAY,CAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,GAAE,MAAM,GAAG,MAAM,GAAG,IAAW;IAS9E;;;;MAIE;IACW,aAAa,CAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,GAAE,MAAM,GAAG,MAAM,GAAG,IAAW;IAS/E,OAAO,CAAC,kBAAkB;CAe7B"}
@@ -0,0 +1,170 @@
1
+ import { AuthError } from 'next-auth';
2
+ import { getSession } from 'next-auth/react';
3
+ export class ApiClient {
4
+ apiBaseUrl;
5
+ static defaultHeaders = {
6
+ 'Content-Type': 'application/json'
7
+ };
8
+ static genericOptions = {
9
+ headers: ApiClient.defaultHeaders
10
+ };
11
+ /**
12
+ * @param {string} apiBaseUrl - The base url of your API service. This should include any path prefixes (like "/api/", "/api/v1/", etc.)
13
+ * @param {string|null} refreshEndpoint — (Optional) The path of your jwt refresh endpoint, if it exists.
14
+ */
15
+ constructor(apiBaseUrl) {
16
+ this.apiBaseUrl = apiBaseUrl;
17
+ }
18
+ async getToken() {
19
+ const session = await getSession();
20
+ if (!session) {
21
+ throw new AuthError('Tried to get session token with no active session!');
22
+ }
23
+ const token = session?.jwt;
24
+ return token;
25
+ }
26
+ async makeRequest(endpoint, options) {
27
+ const url = new URL(endpoint, this.apiBaseUrl);
28
+ const response = await fetch(url, options);
29
+ const data = await response.json();
30
+ return data;
31
+ }
32
+ /**
33
+ * Make an arbitrary request to an endpoint that does not require authentication.
34
+ * @param {string} endpoint - The endpoint to send the request to. Should exclude your API's base url.
35
+ * @param {RequestInit} options — Request options to be passed into fetch()
36
+ */
37
+ async makePublicRequest(endpoint, options) {
38
+ return this.makeRequest(endpoint, options);
39
+ }
40
+ /**
41
+ * Make an arbitrary request using the logged-in user's session.
42
+ * @param {string} endpoint - The endpoint to send the request to. Should exclude your API's base url.
43
+ * @param {RequestInit} options — Request options to be passed into fetch()
44
+ */
45
+ async makePrivateRequest(endpoint, options) {
46
+ const token = this.getToken();
47
+ options.headers = {
48
+ ...options.headers,
49
+ Authorization: `Bearer ${token}`
50
+ };
51
+ return await this.makeRequest(endpoint, options);
52
+ }
53
+ /**
54
+ * Make a GET request to an endpoint that does not require authentication.
55
+ * @param {string} endpoint - The endpoint to send the request to. Should exclude your API's base url.
56
+ */
57
+ async getPublic(endpoint) {
58
+ const options = {
59
+ ...ApiClient.genericOptions,
60
+ method: 'GET'
61
+ };
62
+ return await this.makeRequest(endpoint, options);
63
+ }
64
+ /**
65
+ * Make a GET request using the logged-in user's session.
66
+ * @param {string} endpoint - The endpoint to send the request to. Should exclude your API's base url.
67
+ */
68
+ async getPrivate(endpoint) {
69
+ const options = {
70
+ ...ApiClient.genericOptions,
71
+ method: 'GET'
72
+ };
73
+ return await this.makePrivateRequest(endpoint, options);
74
+ }
75
+ /**
76
+ * Make a POST request to an endpoint that does not require authentication.
77
+ * @param {string} endpoint - The endpoint to send the request to. Should exclude your API's base url.
78
+ * @param {Object} postData — The data to send with your POST request
79
+ */
80
+ async postPublic(endpoint, postData) {
81
+ const options = {
82
+ ...ApiClient.genericOptions,
83
+ method: 'POST',
84
+ body: JSON.stringify({ data: postData })
85
+ };
86
+ return await this.makeRequest(endpoint, options);
87
+ }
88
+ /**
89
+ * Make a POST request using the logged-in user's session.
90
+ * @param {string} endpoint - The endpoint to send the request to. Should exclude your API's base url.
91
+ * @param {Object} postData — The data to send with your POST request
92
+ */
93
+ async postPrivate(endpoint, postData) {
94
+ const options = {
95
+ ...ApiClient.genericOptions,
96
+ method: 'POST',
97
+ body: JSON.stringify({ data: postData })
98
+ };
99
+ return await this.makePrivateRequest(endpoint, options);
100
+ }
101
+ /**
102
+ * Make a PUT request to an endpoint that does not require authentication.
103
+ * @param {string} endpoint - The endpoint to send the request to. Should exclude your API's base url.
104
+ * @param {Object} putData — The data to send with your PUT request
105
+ * @param {string|number|null} id — (Optional) The identifier for the resource to be updated. Will be appended to the provided endpoint path.
106
+ */
107
+ async putPublic(endpoint, putData, id = null) {
108
+ endpoint = this.appendIdToEndpoint(endpoint, id);
109
+ const options = {
110
+ ...ApiClient.genericOptions,
111
+ method: 'PUT',
112
+ body: JSON.stringify({ data: putData })
113
+ };
114
+ return await this.makeRequest(endpoint, options);
115
+ }
116
+ /**
117
+ * Make a PUT request using the logged-in user's session.
118
+ * @param {string} endpoint - The endpoint to send the request to. Should exclude your API's base url.
119
+ * @param {Object} putData — The data to send with your PUT request
120
+ * @param {string|number|null} id — (Optional) The identifier for the resource to be updated. Will be appended to the provided endpoint path.
121
+ */
122
+ async putPrivate(endpoint, putData, id = null) {
123
+ endpoint = this.appendIdToEndpoint(endpoint, id);
124
+ const options = {
125
+ ...ApiClient.genericOptions,
126
+ method: 'PUT',
127
+ body: JSON.stringify({ data: putData })
128
+ };
129
+ return await this.makePrivateRequest(endpoint, options);
130
+ }
131
+ /**
132
+ * Make a DELETE request to an endpoint that does not require authentication.
133
+ * @param {string} endpoint - The endpoint to send the request to. Should exclude your API's base url.
134
+ * @param {string|number|null} id — (Optional) The identifier for the resource to be deleted. Will be appended to the provided endpoint path.
135
+ */
136
+ async deletePublic(endpoint, id = null) {
137
+ endpoint = this.appendIdToEndpoint(endpoint, id);
138
+ const options = {
139
+ ...ApiClient.genericOptions,
140
+ method: 'DELETE'
141
+ };
142
+ return await this.makeRequest(endpoint, options);
143
+ }
144
+ /**
145
+ * Make a DELETE request using the logged-in user's session.
146
+ * @param {string} endpoint - The endpoint to send the request to. Should exclude your API's base url.
147
+ * @param {string|number|null} id — (Optional) The identifier for the resource to be deleted. Will be appended to the provided endpoint path.
148
+ */
149
+ async deletePrivate(endpoint, id = null) {
150
+ endpoint = this.appendIdToEndpoint(endpoint, id);
151
+ const options = {
152
+ ...ApiClient.genericOptions,
153
+ method: 'DELETE'
154
+ };
155
+ return await this.makePrivateRequest(endpoint, options);
156
+ }
157
+ appendIdToEndpoint(endpoint, id = null) {
158
+ if (typeof id === 'number') {
159
+ id = id.toString();
160
+ }
161
+ if (endpoint.slice(-1) !== '/') {
162
+ endpoint = endpoint + '/';
163
+ }
164
+ if (id !== null) {
165
+ endpoint = `${endpoint}${id}`;
166
+ }
167
+ return endpoint;
168
+ }
169
+ }
170
+ //# sourceMappingURL=ApiClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ApiClient.js","sourceRoot":"","sources":["../../src/utils/ApiClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C,MAAM,OAAO,SAAS;IAeN;IAbL,MAAM,CAAC,cAAc,GAAG;QAC3B,cAAc,EAAG,kBAAkB;KACtC,CAAA;IAEM,MAAM,CAAC,cAAc,GAAG;QAC3B,OAAO,EAAE,SAAS,CAAC,cAAc;KACpC,CAAA;IAED;;;MAGE;IACF,YACY,UAAmB;QAAnB,eAAU,GAAV,UAAU,CAAS;IAC3B,CAAC;IAEG,KAAK,CAAC,QAAQ;QAClB,MAAM,OAAO,GAAG,MAAM,UAAU,EAAE,CAAC;QAEnC,IAAI,CAAC,OAAO,EAAE,CAAC;YACX,MAAM,IAAI,SAAS,CAAC,oDAAo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AC7B,QAAQ,GAAG,QAAQ,GAAG,GAAG,CAAC;QAC9B,CAAC;QAED,IAAI,EAAE,KAAK,IAAI,EAAE,CAAC;YACd,QAAQ,GAAG,GAAG,QAAQ,GAAG,EAAE,EAAE,CAAC;QAClC,CAAC;QAED,OAAO,QAAQ,CAAC;IACpB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare const EnabledProviders: () => string[];
2
+ //# sourceMappingURL=enabledProviders.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"enabledProviders.d.ts","sourceRoot":"","sources":["../../src/utils/enabledProviders.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,gBAAgB,gBAoB5B,CAAA"}
@@ -0,0 +1,18 @@
1
+ // This helper function references the project's env file to determine which providers to enable/configure for AuthJS
2
+ export const EnabledProviders = () => {
3
+ let providers = [];
4
+ if (process.env.AUTH_GOOGLE_ID) {
5
+ providers.push("Google");
6
+ }
7
+ if (process.env.AUTH_MICROSOFT_ENTRA_ID_ID) {
8
+ providers.push("MicrosoftEntraID");
9
+ }
10
+ if (process.env.AUTH_OKTA_ID) {
11
+ providers.push("Okta");
12
+ }
13
+ if (process.env.AUTH_CREDENTIALS_ENABLED == "true") {
14
+ providers.push("Credentials");
15
+ }
16
+ return providers;
17
+ };
18
+ //# sourceMappingURL=enabledProviders.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"enabledProviders.js","sourceRoot":"","sources":["../../src/utils/enabledProviders.ts"],"names":[],"mappings":"AAAA,qHAAqH;AACrH,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAAG,EAAE;IACnC,IAAI,SAAS,GAAG,EAAE,CAAC;IAEnB,IAAI,OAAO,CAAC,GAAG,CAAC,cAAc,EAAE,CAAC;QAC/B,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC3B,CAAC;IAED,IAAI,OAAO,CAAC,GAAG,CAAC,0BAA0B,EAAE,CAAC;QAC3C,SAAS,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC;IACrC,CAAC;IAED,IAAI,OAAO,CAAC,GAAG,CAAC,YAAY,EAAE,CAAC;QAC7B,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACzB,CAAC;IAED,IAAI,OAAO,CAAC,GAAG,CAAC,wBAAwB,IAAI,MAAM,EAAE,CAAC;QACnD,SAAS,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;IAChC,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kenny-login",
3
- "version": "0.0.2",
3
+ "version": "0.0.4-beta.1",
4
4
  "author": {
5
5
  "name": "fjorge"
6
6
  },
@@ -13,5 +13,24 @@ declare module "next-auth" {
13
13
  jwt: string
14
14
  } & DefaultSession["user"]
15
15
  }
16
+
17
+ interface Credentials {
18
+ // credentials: {
19
+ email: {
20
+ type: string,
21
+ label: string
22
+ },
23
+ password: {
24
+ type: string,
25
+ label: string
26
+ },
27
+ // },
28
+ authorize,
29
+ }
30
+
31
+ interface AuthProvider {
32
+ id: string,
33
+ name: string
34
+ }
16
35
  }
17
36
 
@@ -1 +0,0 @@
1
- {"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAAA,OAAiB,EAAE,KAAK,cAAc,EAAE,MAAM,WAAW,CAAC;AA6E1D,eAAO,MAAM,IAAI,EAAG,cAAc,CAAC,MAAM,CAAuB,CAAC;AACjE,eAAO,MAAM,QAAQ;;;CAA0B,CAAC;AAChD,eAAO,MAAM,MAAM;cAEoiO,CAAC;YAAyJ,CAAC;yJAFvqO,CAAC;AAC5C,eAAO,MAAM,OAAO;cACmzQ,CAAC;YAA0J,CAAC;4CADt7Q,CAAC"}
package/dist/auth.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"auth.js","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,EAAE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AAM,OAAO,GAAG,cAAc,CAAC,OAAO,CAAC"}
@@ -1,2 +0,0 @@
1
- export declare function SignInForm(): import("react").JSX.Element;
2
- //# sourceMappingURL=signin-form.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"signin-form.d.ts","sourceRoot":"","sources":["../../src/components/signin-form.tsx"],"names":[],"mappings":"AAAA,wBAAgB,UAAU,gCAiCzB"}
@@ -1,29 +0,0 @@
1
- export function SignInForm() {
2
- return (<div className="kl-sign-in-form--wrapper">
3
- <form id="signInForm" name="Sign In" className="kl-sign-in-form">
4
- <title>Sign in</title>
5
- <div className="kl-sign-in-form--field-group">
6
- <label htmlFor="email">
7
- Email
8
- </label>
9
- <input name="email" id="email"/>
10
- </div>
11
- <div className="kl-sign-in-form--field-group">
12
- <label htmlFor="password">
13
- Password
14
- </label>
15
- <input name="password" id="password"/>
16
- </div>
17
- <button type="submit" className="kl-sign-in-form--submit-button">
18
- Sign In
19
- </button>
20
- </form>
21
- {/* TODO: Make this a loop over providers */}
22
- <form className="kl-sign-in-form--providers-list">
23
- <button type="submit">
24
- <span>Sign in with [provider name]</span>
25
- </button>
26
- </form>
27
- </div>);
28
- }
29
- //# sourceMappingURL=signin-form.jsx.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"signin-form.jsx","sourceRoot":"","sources":["../../src/components/signin-form.tsx"],"names":[],"mappings":"AAAA,MAAM,UAAU,UAAU;IACxB,OAAO,CACL,CAAC,GAAG,CAAC,SAAS,CAAC,0BAA0B,CACvC;MAAA,CAAC,IAAI,CACH,EAAE,CAAC,YAAY,CACf,IAAI,CAAC,SAAS,CACd,SAAS,CAAC,iBAAiB,CAE3B;QAAA,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,CACrB;QAAA,CAAC,GAAG,CAAC,SAAS,CAAC,8BAA8B,CAC3C;UAAA,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CACpB;;UACF,EAAE,KAAK,CACP;UAAA,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,OAAO,EAChC;QAAA,EAAE,GAAG,CACL;QAAA,CAAC,GAAG,CAAC,SAAS,CAAC,8BAA8B,CAC3C;UAAA,CAAC,KAAK,CAAC,OAAO,CAAC,UAAU,CACvB;;UACF,EAAE,KAAK,CACP;UAAA,CAAC,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC,UAAU,EACtC;QAAA,EAAE,GAAG,CACL;QAAA,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,gCAAgC,CAC9D;;QACF,EAAE,MAAM,CACV;MAAA,EAAE,IAAI,CACN;MAAA,CAAC,2CAA2C,CAC1C;QAAA,CAAC,IAAI,CAAC,SAAS,CAAC,iCAAiC,CAC/C;UAAA,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CACnB;YAAA,CAAC,IAAI,CAAC,4BAA4B,EAAE,IAAI,CAC1C;UAAA,EAAE,MAAM,CACV;QAAA,EAAE,IAAI,CACV;IAAA,EAAE,GAAG,CAAC,CACP,CAAA;AACH,CAAC"}