Skip to content

Instantly share code, notes, and snippets.

View OmkarK45's full-sized avatar
💫
Trust the process

Omkar Kulkarni OmkarK45

💫
Trust the process
View GitHub Profile
@OmkarK45
OmkarK45 / [...nextauth].tsx
Last active April 3, 2022 10:16
Next Auth with custom backend that returns JWT
import NextAuth from "next-auth";
import CredentialsProvider from "next-auth/providers/credentials";
type TA_Token = {
token: string;
user_id: number;
};
export default NextAuth({
providers: [
@OmkarK45
OmkarK45 / useConnection.ts
Created January 12, 2022 05:40
Convert Relay Pagination Response to normal list
import { useMemo } from 'react';
type Connection<T> = {
readonly edges : readonly ({
readonly node? : T | null ;
readonly cursor?:string
} | null)[];
};
export function useConnection<T>(connection?:Connection<T>){
import { ActionType } from '../actionTypes'
import { Action } from '../actions'
interface RepositoriesState {
loading: boolean
error: string | null
data: string[]
}
const initialState = {
@OmkarK45
OmkarK45 / test.ts
Created November 22, 2021 19:41
Created from Remix Form!
export ok = 45
@OmkarK45
OmkarK45 / Button.tsx
Created November 8, 2021 13:32
Reusable TailwindCSS Button Component with loading and icon
import clsx from 'clsx'
import ButtonOrLink, { Props as ButtonOrLinkProps } from '../ButtonOrLink'
export interface Props extends ButtonOrLinkProps {
variant?: 'solid' | 'secondary' | 'white' | 'dark' | 'danger'
loading?: boolean
size?: 'xs' | 'sm' | 'base' | 'lg' | 'xl'
className?: string
}
@OmkarK45
OmkarK45 / AuthController.ts
Created November 8, 2021 13:29
Auth handler that handles new signups on the platform
export const signUpHandler: RequestHandler<{}, {}, SignUpBody> = async (
req,
res
) => {
const { firstName, lastName, email, password } = req.body
const isAlreadyRegistered = await User.findOne({
email,
})
if (isAlreadyRegistered) {
@OmkarK45
OmkarK45 / ValidationMiddleware.ts
Created November 8, 2021 13:27
Validate Incoming Body Against a yup schema
import { NextFunction, Request, Response } from 'express'
import { BaseSchema } from 'yup'
import { MixedSchema } from 'yup/lib/mixed'
/**
* This middleware checks the req.body against an yup schema provided in it
* @example
* ```
* validate(incomingRequestBody, incomingBodySchema)
*
@OmkarK45
OmkarK45 / db.ts
Created November 8, 2021 13:25
Connection to MongoDB
import mongoose from 'mongoose'
import log from '../utils/logger'
/**
* @description - This function creates connection to the database with given options.
* Resolves to connection with DB or Failure with an error message
* */
export const makeConnection = async () => {
await mongoose
.connect(
import clsx from 'clsx'
import React, { useCallback, useEffect } from 'react'
import { useDropzone } from 'react-dropzone'
import { useFormContext } from 'react-hook-form'
import { HiOutlinePhotograph } from 'react-icons/hi'
import { Alert } from '../Alert'
interface FileInputProps
extends React.DetailedHTMLProps<
React.InputHTMLAttributes<HTMLInputElement>,
import { createContext, useContext, useEffect, useState } from 'react'
import { getUser, logout } from 'services/axios'
/**
* getUser() -> Helper function to fetch user information. (basically an axios call)
* logout() -> Helper function to logout users
*/
const AuthContext = createContext()