Skip to content

Instantly share code, notes, and snippets.

View thisismydesign's full-sized avatar

Csaba Apagyi thisismydesign

View GitHub Profile
@thisismydesign
thisismydesign / google-oauth.controller.ts
Last active March 19, 2024 19:08
OAuth2 in NestJS for social login (Google, Facebook, Twitter, etc) /1
import { Controller, Get, Req, Res, UseGuards } from '@nestjs/common';
import { Request, Response } from 'express';
import { GoogleOauthGuard } from './google-oauth.guard';
@Controller('auth/google')
export class GoogleOauthController {
constructor(private jwtAuthService: JwtAuthService) {}
@Get()
@UseGuards(GoogleOauthGuard)
@thisismydesign
thisismydesign / view.controller.ts
Last active January 8, 2024 06:57
NestJS + Next.js /2 View Module
import { Controller, Get, Res, Req } from '@nestjs/common';
import { Request, Response } from 'express';
import { parse } from 'url';
import { ViewService } from './view.service';
@Controller('/')
export class ViewController {
constructor(private viewService: ViewService) {}
@thisismydesign
thisismydesign / test.js
Created February 10, 2019 02:27
Mocking per test case with Jest /1
describe("<Component />", () => {
it("works", () => {
// ...
}):
describe("when something silly happens", () => {
beforeEach(() => {
jest.mock("MyOtherComponent", () => {
// ...
})
@thisismydesign
thisismydesign / package.json
Last active September 6, 2023 12:47
Typed GraphQL queries and results /2 Generate types
{
"scripts": {
"client:generate:schema": "zeus <path-ot-schema> <output-folder> --typescript --apollo"
}
}
@thisismydesign
thisismydesign / home.tsx
Last active September 6, 2023 12:46
NestJS + Next.js /3 Home page
import React from 'react';
import { NextPage } from 'next';
const Home: NextPage = () => {
return <h1>Hello from NextJS! - Home</h1>;
};
export default Home;
@thisismydesign
thisismydesign / test.js
Last active September 6, 2023 12:46
Mocking per test case with Jest /1
jest.mock("MyOtherComponent", () => {
return require
.requireActual("TestUtils")
.mockOriginalFunctionality("MyOtherComponent");
});
describe("<Component />", () => {
it("works", () => {
// MyOtherComponent works as usual
}):
@thisismydesign
thisismydesign / install.sh
Last active September 6, 2023 12:44
NestJS + Next.js /1 Install
yarn add next react react-dom
yarn add --dev @types/react @types/react-dom
@thisismydesign
thisismydesign / example data
Last active September 6, 2023 12:44
NestJS Google OAuth
this.oauth2Client.getTokenInfo(
req.user.accessToken,
);
tokenInfo {
web_1 | expiry_date: 1619210156644,
web_1 | scopes: [
web_1 | 'https://www.googleapis.com/auth/userinfo.email',
web_1 | 'https://www.googleapis.com/auth/userinfo.profile',
web_1 | 'openid'
web_1 | ],
@thisismydesign
thisismydesign / .eslintrc.js
Last active September 6, 2023 12:43
NestJS + Next.js /4 Folder structure & config
// src/client/.eslintrc.js
// Your custom ESLint file for React, applied only to src/client automatically
module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
project: 'src/client/tsconfig.json',
sourceType: 'module',
},
plugins: ['@typescript-eslint/eslint-plugin'],
@thisismydesign
thisismydesign / jwt-auth.guard.ts
Last active September 6, 2023 12:42
OAuth2 in NestJS for social login (Google, Facebook, Twitter, etc) /2
import { Injectable } from '@nestjs/common';
import { AuthGuard } from '@nestjs/passport';
@Injectable()
export class JwtAuthGuard extends AuthGuard('jwt') {}