Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add auth link components #32

Merged
merged 1 commit into from
Jun 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { ReactElement } from "react";
import {ReactElement} from 'react';

export declare function useKindeAuth(): State;

export declare function KindeProvider({
children,
children
}: {
children: any;
}): ReactElement<State>;

export declare function handleAuth(): any;

export type User = {
Expand All @@ -29,9 +30,9 @@ export type KindePermission = {
orgCode: string;
};

export type KindeFlagTypeCode = "b" | "i" | "s";
export type KindeFlagTypeCode = 'b' | 'i' | 's';

export type KindeFlagTypeValue = "boolean" | "integer" | "string";
export type KindeFlagTypeValue = 'boolean' | 'integer' | 'string';

export type KindeFlag = {
code: string;
Expand Down
9 changes: 9 additions & 0 deletions server/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
import {ReactElement, LinkHTMLAttributes} from 'react';
import {NextRequest} from 'next/server';

export declare function RegisterLink(props): ReactElement<LinkHTMLAttributes>;

export declare function LoginLink(props): ReactElement<LinkHTMLAttributes>;

export declare function CreateOrgLink(props): ReactElement<LinkHTMLAttributes>;

export declare function LogoutLink(props): ReactElement<LinkHTMLAttributes>;

export type KindeUser = {
given_name: string | null;
id: string | null;
Expand Down
12 changes: 12 additions & 0 deletions src/components/CreateOrgLink.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import React from 'react';

export function CreateOrgLink({children, orgName, ...props}) {
return (
<a
href={`/api/auth/create_org${orgName ? `?org_name=${orgName}` : ''}`}
{...props}
>
{children}
</a>
);
}
12 changes: 12 additions & 0 deletions src/components/LoginLink.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import React from 'react';

export function LoginLink({children, orgCode, ...props}) {
return (
<a
href={`/api/auth/login${orgCode ? `?org_code=${orgCode}` : ''}`}
{...props}
>
{children}
</a>
);
}
9 changes: 9 additions & 0 deletions src/components/LogoutLink.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React from 'react';

export function LogoutLink({children, ...props}) {
return (
<a href="/api/auth/logout" {...props}>
{children}
</a>
);
}
12 changes: 12 additions & 0 deletions src/components/RegisterLink.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import React from 'react';

export function RegisterLink({children, orgCode, ...props}) {
return (
<a
href={`/api/auth/register${orgCode ? `?org_code=${orgCode}` : ''}`}
{...props}
>
{children}
</a>
);
}
4 changes: 1 addition & 3 deletions src/handlers/appRouter/register.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ import {prepareForRedirect} from '../../utils/appRouter/prepareForRedirect';
import {redirect} from 'next/navigation';

export const register = async (request) => {
const org_name = request.nextUrl.searchParams.get('org_name');
const org_code = request.nextUrl.searchParams.get('org_code');
const is_create_org = request.nextUrl.searchParams.get('is_create_org');

const options = {org_name, org_code, is_create_org};
const options = {org_code};

const authUrl = prepareForRedirect(options, 'register');

Expand Down
5 changes: 5 additions & 0 deletions src/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,8 @@ export const getKindeServerSession = () => {
};

export {authMiddleware} from '../authMiddleware/authMiddleware';

export {RegisterLink} from '../components/RegisterLink';
export {LoginLink} from '../components/LoginLink';
export {LogoutLink} from '../components/LogoutLink';
export {CreateOrgLink} from '../components/CreateOrgLink';