Skip to content

Instantly share code, notes, and snippets.

View atakde's full-sized avatar
🎯
Focusing

Atakan Demircioğlu atakde

🎯
Focusing
View GitHub Profile
@atakde
atakde / _middleware.js
Last active April 22, 2022 22:40
Nextjs authentication middleware
import { NextResponse } from 'next/server';
import { verifyToken } from '../middleware/utils';
export async function middleware(req) {
const { cookies } = req;
const { origin } = req.nextUrl;
const jwt = cookies.token; // get jwt token
const protectedPaths = ['/share'];
@atakde
atakde / auth.js
Created April 24, 2022 21:42
Node.js JWT Authentication With HTTP Only Cookie
import bcrypt from 'bcryptjs';
import jwt from 'jsonwebtoken';
import { PrismaClient } from '@prisma/client';
import HTTPMethod from 'http-method-enum';
import HTTP_STATUS_CODES from 'http-status-enum';
import { serialize } from 'cookie';
const prisma = new PrismaClient();
const KEY = process.env.JWT_KEY;
@atakde
atakde / logout.js
Created April 24, 2022 22:05
Node.js JWT Logout With HTTP Only Cookie
import { serialize } from 'cookie';
export default function logout(req, res) {
const { cookies } = req;
const jwt = cookies.token;
if (!jwt) {
return res.status(401).json({
status: 'error',
<?php
interface FlyingCreature
{
public function fly();
}
interface FeatheredCreature
{
public function molt();
<?php
abstract class Debugger
{
abstract public function debug($message);
}
class BrowserDebugger extends Debugger
{
public function debug($message)
@atakde
atakde / Singleton.php
Created June 27, 2022 20:37
Design Patterns: Singleton PHP Example
<?php
class Singleton
{
private static $instance = null;
/**
* prevent from creating multiple instances
*/
@atakde
atakde / Builder.php
Created June 27, 2022 21:13
Builder Pattern PHP Example
<?php
abstract class Vecihle
{
public $engine;
public $wheel;
public $doors;
}
class Car extends Vecihle
@atakde
atakde / SimpleFactory.php
Created June 27, 2022 21:30
Simple Factory Design Pattern PHP Example
<?php
class Car
{
public function hello()
{
echo "Hello!";
}
}
@atakde
atakde / AbstractFactory.php
Created June 28, 2022 21:29
Abstract Factory Design Pattern PHP Example
<?php
interface CarInterface
{
public function getBrand(): string;
public function getPrice(): int;
}
interface MotorcycleInterface
{
@atakde
atakde / StaticFactory.php
Last active June 29, 2022 16:58
Static Factory Design Pattern Example With PHP
<?php
class Customer
{
public function hello()
{
echo "Hello from customer!";
}
}