-import type {NextRequest} from 'next/server';
-import {redirect} from 'next/navigation';
+import type { NextRequest } from 'next/server';
+import { redirect } from 'next/navigation';
import initMiroAPI from '../../../utils/initMiroAPI';
// handle redirect with code and exchange it for the access token
export async function GET(request: NextRequest) {
- const {miro, userId} = initMiroAPI();
+ const { miro, userId } = initMiroAPI();
+
+ const awaitedUserId = await userId();
// Make sure the code is in query parameters
const code = request.nextUrl.searchParams.get('code');
}
try {
- await miro.exchangeCodeForAccessToken(userId, code);
+ await miro.exchangeCodeForAccessToken(awaitedUserId, code);
} catch (error) {
redirect('/?error');
}
'use server';
-import { AppCardItem, CardItem, DocumentItem, EmbedItem, FrameItem, ImageItem, Item, ShapeItem, StickyNoteItem, TextItem } from '@mirohq/miro-api';
+import { AppCardItem, Board, CardItem, DocumentItem, EmbedItem, FrameItem, ImageItem, Item, ShapeItem, StickyNoteItem, TextItem } from '@mirohq/miro-api';
import initMiroAPI from '../utils/initMiroAPI';
import { Path, Shape, Slide, Whiteboard, Image, neoboardWhiteboardWidth, neoboardWhiteboardHeight } from './neoboardTypes';
import { stripHtml } from 'string-strip-html';
if (item.parent.id === frameId) {
switch (item.type) {
case 'shape':
- const shape = convertShape(item as ShapeItem);
+ const shape = await convertShape(item as ShapeItem, board);
if (shape) {
slide.elements.push(shape);
}
return transformedBoard;
}
-function convertShape(item: ShapeItem): Shape | undefined {
+async function convertShape(item: ShapeItem, board: Board): Promise<Shape | undefined> {
let shapeType = item.data?.shape;
let borderRadius = 0;
if (shapeType !== 'rectangle' && shapeType !== 'circle' && shapeType !== 'ellipse' && shapeType !== 'triangle' && shapeType !== 'round_rectangle') {
}
if (shapeType === 'round_rectangle') {
shapeType = 'rectangle';
- borderRadius = 10;
+ borderRadius = 25;
}
+ // Get shape item from Miro API
+ item = await board.getItem(item.id) as ShapeItem;
+
const opacity = item.style?.fillOpacity ?? (item.style?.fillColor ? "1.0" : "0.0");
const borderColorOpacity = item.style?.borderOpacity ?? "1.0";
fillColor: item.style?.fillColor ?? "#ffffff",
strokeColor: 'transparent',
strokeWidth: 0,
- borderRadius: 10,
+ borderRadius: 25,
text: stripHtml(item.data?.content ?? "").result,
textAlignment: (item.style?.textAlign ?? "left") as "left" | "center" | "right",
textColor: 'black',
--- /dev/null
+"use server";
+
+import { redirect } from "next/navigation";
+import { logoutMiroAPI } from "../utils/initMiroAPI";
+
+export default async function logout() {
+ await logoutMiroAPI();
+ redirect("/");
+}
\ No newline at end of file
--- /dev/null
+"use server";
+
+import logout from "./logoutAction";
+
+export default async function Logout() {
+ return (
+ <div>
+ <h3>Logout</h3>
+ <form action={logout}>
+ <button className="button button-danger" type="submit">
+ Logout
+ </button>
+ </form>
+ </div>
+ )
+}
\ No newline at end of file
import initMiroAPI from '../utils/initMiroAPI';
import '../assets/style.scss';
import SelectionFormComponent from './selectionFormComponent';
+import Logout from './logoutComponent';
const getBoards = async () => {
const { miro, userId } = initMiroAPI();
return (
<div>
<h3>Login</h3>
- <a className="button button-primary" href={authUrl} target="_blank">
+ <a className="button button-primary" href={authUrl}>
Login
</a>
</div>
return <div>Loading...</div>;
}
- return (<><SelectionFormComponent boards={safeBoards} /></>);
+ return (
+ <>
+ <Logout />
+ <hr className="cs1 ce12" />
+ <SelectionFormComponent boards={safeBoards} />
+ </>
+ );
}
const tokensCookie = 'miro_tokens';
+export async function logoutMiroAPI() {
+ const { miro, userId } = initMiroAPI();
+ const userIdAwaited = await userId();
+
+ if (userIdAwaited) {
+ await miro.as(userIdAwaited).revokeToken();
+ }
+
+ const cookieInstance = await cookies();
+ cookieInstance.delete('miro_tokens');
+}
+
export default function initMiroAPI() {
const cookieInstance = cookies();