Solved

Shopify cli (yarn dev) auth failed under Docker

h_smalian
Shopify Partner
2 1 2

Hi! I'm new here and want to create an  application for shopify. I use docker and php (laravel) template. When I run "yarn dev" inside my php container I get link for log in, I copy the link and log in. But after I am redirected to this url: http://127.0.0.1:3456/?code..... and I get "site can't be reached" error

 

my docker-compose file:

version: '3'

services:
    web-server-shopify:
        build:
            dockerfile: nginx.Dockerfile
            context: ./docker/nginx
        restart: always
        container_name: web-server-shopify
        image: nginx:1.20
        ports:
            - '80:80'
            - '8080:8080'
            - '9292:9292'
            - '3456:3456'
        volumes:
            - ./source:/app
            - ./docker/nginx/conf.d:/etc/nginx/conf.d
        depends_on:
          - php-shopify
        
    php-shopify:
        container_name: php-shopify
        build:
            dockerfile: ./docker/php8.1/php.Dockerfile
            context: .
        volumes:
          - "./source:/app"
          - ./docker/php8.1/php.ini:/usr/local/etc/php/conf.d/php.ini
          - ~/.ssh:/root/.ssh
        depends_on:
            - mysql-server-shopify

    mysql-server-shopify:
        container_name: mysql-server-shopify
        image: mysql:5.7
        restart: always
        environment:
            MYSQL_ROOT_PASSWORD: root
            MYSQL_USER: [USER_HERE]
            MYSQL_PASSWORD: [USER_PASS_HERE]
            MYSQL_DATABASE: shopify
        command:
            - "mysqld"
            - "--local_infile=true"
        ports:
            - "3332:3306"

    phpmyadmin-shopify:
        container_name: phpmyadmin-shopify
        image: phpmyadmin/phpmyadmin:5.0.1
        restart: always
        environment:
            PMA_HOST: mysql-server-shopify
            PMA_USER: root
            PMA_PASSWORD: root
            UPLOAD_LIMIT: 50M
        ports:
            - "5024:80"
        depends_on:
            - mysql-server-shopify

 here is my php.Dockerfile

 

FROM php:8.1-fpm

# Set the working directory inside the container
WORKDIR /app

# Install Shopify CLI dependencies
RUN apt-get update && apt-get install -y \
    wget \
    curl \
    gcc \
    g++ \
    make \
    build-essential \
    zlib1g-dev \
    libssl-dev \
    libreadline-dev \
    libyaml-dev \
    libsqlite3-dev \
    sqlite3 \
    libxml2-dev \
    libxslt1-dev \
    libcurl4-openssl-dev \
    libffi-dev \
    autoconf \
    libncurses5-dev \
    bison \
    libgdbm-dev \
    git \
    lsof \
    socat \
    software-properties-common \
    default-libmysqlclient-dev \
    libpq-dev \
    unzip \
    imagemagick \
    sudo \
    libzip-dev \
         && docker-php-ext-install zip

# InstallX-debug
RUN set -x \
    && pecl install -f xdebug-3.0.0 \
    && docker-php-ext-enable xdebug

#Install PDO (need for composer laravel)    
RUN docker-php-ext-install pdo pdo_mysql
    
# install nodejs
RUN curl -sL https://deb.nodesource.com/setup_16.x | sudo -E bash -
RUN apt install nodejs

# install yarn
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
RUN apt-get update && apt-get install yarn --yes

# install composer

RUN curl -sS https://getcomposer.org/installer | \
  php -- --install-dir=/usr/local/bin --filename=composer
  
RUN mkdir -p /home/appuser/.config/shopify && chmod -R 777 /home/appuser/.config/shopify


      
# Expose port 9000 and start php-fpm server
EXPOSE 9000

CMD ["php-fpm"]

 

my conf file:

server {
    listen 80;
    index index.php index.html;
    error_log  /var/log/nginx/error.log;
    access_log /var/log/nginx/access.log;
    root /app/advox-app/web/public; #advox-app is your application name
    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass php-shopify:9000;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
    }
    location / {
        try_files $uri $uri/ /index.php?$query_string;
        gzip_static on;
    }
}

 

also, when open http://localhost I get error:

TypeError
Shopify\Utils::sanitizeShopDomain(): Argument #1 ($shop) must be of type string, null given, called in /app/advox-app/web/app/Lib/AuthRedirection.php on line 17

 

But seems like this error connects to  "yarn dev" command. Please, help me. Thanks!

Accepted Solution (1)

h_smalian
Shopify Partner
2 1 2

This is an accepted solution.

Well, if smb face this issue, you can resolve like that:

 

log in you account, after when you are redirected to this url - http://127.0.0.1:3456/?[URL_PARAMS_HERE]

 

Just do this:

 

1 - expose 3456 port for php container instead of webserver

2 - log in shopify partner, when you are redirected to this "http://127.0.0.1:3456/?[URL_PARAMS_HERE] just do this:

   2.1 - open a new tab in your terminal, go to php container again. go to your project dir and run:

   wget 'http://127.0.0.1:3456/?code=[CODE]&state=[STATE]' - don't forget to use quotes!

   

   2.2 - open your first terminal tab and your command will proceed working.

View solution in original post

Reply 1 (1)

h_smalian
Shopify Partner
2 1 2

This is an accepted solution.

Well, if smb face this issue, you can resolve like that:

 

log in you account, after when you are redirected to this url - http://127.0.0.1:3456/?[URL_PARAMS_HERE]

 

Just do this:

 

1 - expose 3456 port for php container instead of webserver

2 - log in shopify partner, when you are redirected to this "http://127.0.0.1:3456/?[URL_PARAMS_HERE] just do this:

   2.1 - open a new tab in your terminal, go to php container again. go to your project dir and run:

   wget 'http://127.0.0.1:3456/?code=[CODE]&state=[STATE]' - don't forget to use quotes!

   

   2.2 - open your first terminal tab and your command will proceed working.