Skip to content

Instantly share code, notes, and snippets.

@jorgemasta
jorgemasta / renew-graphql-token.js
Last active October 13, 2023 23:01
Add `BIGCOMMERCE_STOREFRONT_API_TOKEN` to `.env`
import fs from 'fs'
import axios from 'axios'
const { REACT_APP_API_ENDPOINT, BIGCOMMERCE_STORE_HASH, BIGCOMMERCE_STORE_API_TOKEN } = process.env
// REACT_APP_API_ENDPOINT=http://localhost:3030
// BIGCOMMERCE_STORE_HASH=WQiOjEsImN
// BIGCOMMERCE_STORE_API_TOKEN=FsaG9zdDozMDMwIl0sImVhdCI6MTdww3
@jorgemasta
jorgemasta / functions.php
Created October 1, 2021 11:42
Authenticate user in WordPress with code
<?php
// Authenticate wordpress user 1 (ID)
wp_set_auth_cookie(1);
/**
* If doesn't works, try this:
wp_clear_auth_cookie();
wp_set_current_user ( 1 );
wp_set_auth_cookie ( 1 );
@jorgemasta
jorgemasta / sso-login.ts
Last active January 3, 2024 14:06
SSO Login to BigCommerce using a (Next) API Route
import type { NextApiHandler, NextApiRequest, NextApiResponse } from 'next'
import jwt from 'jsonwebtoken';
import {v4 as uuidv4} from 'uuid';
import concatHeader from '../utils/concat-cookie'
import getConfig from '../utils/get-config'
function getSsoLoginUrl(customerId: number, storeHash: string, storeUrl: string, clientId: string, clientSecret: string) {
const dateCreated = Math.round((new Date()). getTime() / 1000);
const payload = {
"iss": clientId,
@jorgemasta
jorgemasta / custom-query.ts
Last active November 16, 2023 07:07
Custom GraphQL query to get products with related products
import { productPrices, multipleChoiceOptionFragment } from '@framework/api/fragments/product';
const productInfoFragment = /* GraphQL */ `
fragment productInfo on Product {
entityId
name
path
brand {
entityId
}
@jorgemasta
jorgemasta / index.js
Created June 23, 2020 14:53
Disable yellow warning in React Native
console.disableYellowBox = true;
// Your react-native app
@jorgemasta
jorgemasta / appcenter-post-build.sh
Created June 12, 2020 12:21
Automatically upload react-native source maps to Bugsnag from Appcenter
#!/usr/bin/env bash
# Prevent send to bugsnag in not selected branches
if [ "$APPCENTER_BRANCH" != "production" ] && [ "$APPCENTER_BRANCH" != "qa" ] && [ "$APPCENTER_BRANCH" != "staging" ]
then
echo "This branch is not in the selected ones:" $APPCENTER_BRANCH
exit
fi
# Set platform
echo "Setting Platform..."
import { Linking } from 'react-native'
import BugTracker from 'BUGSNAG/SENTRY/FIREBASE...'
export const openUnsafeUrl = async (url: string): void => {
try {
const supported = await Linking.canOpenURL(url)
if (!supported) {
BugTracker.sendMessage(`Can't handle url: ${url}`)
}
await Linking.openURL(url)