Gaurang
Gaurang
Explore posts from servers
KPCKevin Powell - Community
Created by Gaurang on 5/6/2024 in #front-end
Vanilla Css "Isolated Scroll" section
Gonna give it a try as soon as i get the chance will report back
7 replies
KPCKevin Powell - Community
Created by Gaurang on 5/6/2024 in #front-end
Vanilla Css "Isolated Scroll" section
In the example those "localized" scrolls are used to "scrub" through the video on the right. I don't necessarily expect to use video, but I might opt for a gif instaed.
7 replies
KPCKevin Powell - Community
Created by Gaurang on 5/6/2024 in #front-end
Vanilla Css "Isolated Scroll" section
That wouldn't just hijack the scroll for me tho right? I'd still have to use something like scroll snapping to isolate the scroll in the section right?
7 replies
TTCTheo's Typesafe Cult
Created by EQ on 1/1/2023 in #questions
NextJS middleware
You can just as easily use getSession to get the current session if you're including your user roles on the session object.
4 replies
TTCTheo's Typesafe Cult
Created by EQ on 1/1/2023 in #questions
NextJS middleware
Oddly i just shared this in another post earlier... this is how I'm currently handling this in my applications:
import { getToken } from "next-auth/jwt";
import { NextResponse } from "next/server";

import type { NextRequest } from "next/server";

export async function middleware(req: NextRequest) {
//token will exist if user is logged in
const token = await getToken({ req, secret: process.env.NEXTAUTH_SECRET });

const { pathname } = req.nextUrl;

const whitelist: string[] = ["api/auth", "/"];

if (whitelist.includes(pathname) || token) {
return NextResponse.next();
}

//redirect them to login if they don't have token and are
//requesting a protected route
const protectedRoutes: string[] = ["/admin"];

const isProtectedRoute = protectedRoutes.every((path) => path === pathname);

if (!token && isProtectedRoute) {
return NextResponse.redirect(new URL("/auth/signin", req.url));
}
});
}

export const config = {
matcher: "/",
};
import { getToken } from "next-auth/jwt";
import { NextResponse } from "next/server";

import type { NextRequest } from "next/server";

export async function middleware(req: NextRequest) {
//token will exist if user is logged in
const token = await getToken({ req, secret: process.env.NEXTAUTH_SECRET });

const { pathname } = req.nextUrl;

const whitelist: string[] = ["api/auth", "/"];

if (whitelist.includes(pathname) || token) {
return NextResponse.next();
}

//redirect them to login if they don't have token and are
//requesting a protected route
const protectedRoutes: string[] = ["/admin"];

const isProtectedRoute = protectedRoutes.every((path) => path === pathname);

if (!token && isProtectedRoute) {
return NextResponse.redirect(new URL("/auth/signin", req.url));
}
});
}

export const config = {
matcher: "/",
};
4 replies
TTCTheo's Typesafe Cult
Created by noctate on 1/2/2023 in #questions
clean way to protect page and redirect
I've been using the middleware solution for awhile and it's been working pretty well for me. It's extended from the logic in the docs: https://nextjs.org/docs/advanced-features/middleware
import { getToken } from "next-auth/jwt";
import { NextResponse } from "next/server";

import type { NextRequest } from "next/server";

export async function middleware(req: NextRequest) {
//token will exist if user is logged in
const token = await getToken({ req, secret: process.env.NEXTAUTH_SECRET });

const { pathname } = req.nextUrl;

const whitelist: string[] = ['api/auth', '/'];

if (whitelist.includes(pathname) || token) {
return NextResponse.next();
}

//redirect them to login if they don't have token and are requesting a protected route
const protectedRoutes: string[] = ["/admin"];

const isProtectedRoute = protectedRoutes.every((path) => path === pathname);

if (!token && isProtectedRoute) {
console.log("redirect to login middleware", null);
return NextResponse.redirect(new URL("/auth/signin", req.url));
}
});
}

export const config = {
matcher: "/",
};
import { getToken } from "next-auth/jwt";
import { NextResponse } from "next/server";

import type { NextRequest } from "next/server";

export async function middleware(req: NextRequest) {
//token will exist if user is logged in
const token = await getToken({ req, secret: process.env.NEXTAUTH_SECRET });

const { pathname } = req.nextUrl;

const whitelist: string[] = ['api/auth', '/'];

if (whitelist.includes(pathname) || token) {
return NextResponse.next();
}

//redirect them to login if they don't have token and are requesting a protected route
const protectedRoutes: string[] = ["/admin"];

const isProtectedRoute = protectedRoutes.every((path) => path === pathname);

if (!token && isProtectedRoute) {
console.log("redirect to login middleware", null);
return NextResponse.redirect(new URL("/auth/signin", req.url));
}
});
}

export const config = {
matcher: "/",
};
9 replies
TTCTheo's Typesafe Cult
Created by Perfect on 12/30/2022 in #questions
GitHub Pinned Repository Behavior
beautiful dnd is a good solution you should be fine with this.
22 replies
TTCTheo's Typesafe Cult
Created by Son on 11/21/2022 in #questions
TRPC Testing Wrapper - Unit Testing components that contain a query (Not testing the query it self)
9 replies
TTCTheo's Typesafe Cult
Created by Son on 11/21/2022 in #questions
TRPC Testing Wrapper - Unit Testing components that contain a query (Not testing the query it self)
For posterity I also came across a few other useful examples which I think it's worth documenting here:
9 replies
TTCTheo's Typesafe Cult
Created by Son on 11/21/2022 in #questions
TRPC Testing Wrapper - Unit Testing components that contain a query (Not testing the query it self)
Also includes setup/config for cypress testing as well.
9 replies
TTCTheo's Typesafe Cult
Created by Son on 11/21/2022 in #questions
TRPC Testing Wrapper - Unit Testing components that contain a query (Not testing the query it self)
Leaving this here for my future self and anyone else how may run into this issue as well.
9 replies
TTCTheo's Typesafe Cult
Created by Son on 11/21/2022 in #questions
TRPC Testing Wrapper - Unit Testing components that contain a query (Not testing the query it self)
Thanks for documenting your journey setting up testing with trpc. This really helped me get oriented although I eventually went for a similar solution shown here: https://github.com/mthomps4/trpc-next-auth-spike/blob/ae259ca5d1e09fce206d8a7e985646ad16c46a37/tests/utils.tsx
9 replies