delucis / astro-netlify-cms

Integration to add Netlify CMS’s admin dashboard to any Astro project
161 stars 21 forks source link

I can't log in to Netlify CMS #44

Closed Kuldas closed 1 year ago

Kuldas commented 1 year ago

Hi @delucis πŸ‘‹

I am a complete newbie to Astro and Netlify CMS. I have a problem logging into the Netlify CMS administration.

I have installed astro-netlify-cms and edited the astro.config.mjs config as needed (see below).

import { defineConfig } from 'astro/config';
import NetlifyCMS from 'astro-netlify-cms';
import preact from "@astrojs/preact";

export default defineConfig({
  integrations: [
    NetlifyCMS({
      config: {
        backend: {
          name: 'git-gateway',
          branch: 'master',
        },
        collections:  [
          {
            name: 'posts',
            label: 'Blog posts',
            folder: 'src/pages/posts',
            create: true,
            delete: true,
            fields: [
            { name: 'title', widget: 'string', label: 'Post title' },
            { name: 'body', widget: 'markdown', label: 'Post body'},
            ],
          },
        ],
      },
    }),
    preact()]
});

I committed everything to the repository on GitHub. In the netlify app I added a new site with the following settings:

Base directory: Not set Build command: npm run build Publish directory: dist Deploy log visibility: Logs are public Build status: Active

I also enabled Identity and Git gateway. The first thing I noticed is that the site doesn't show the login widget. When I add /admin, it takes me to the Netlify CMS login page, but shouldn't the registration option pop up first?

You can check the site yourself - www.stpn.dev Then here is my repo - stpn-astro

I don't really know where to look for the error and that's why I would like to ask for help.

delucis commented 1 year ago

Hi @Kuldas! Cool to see you completed the Astro tutorial β€” nice work! πŸ™Œ

The first thing I noticed is that the site doesn't show the login widget.

This is normal: the widget is available when you navigate to /admin but not visible elsewhere. You can add a link to /admin to let people login to your site footer or wherever you’d like it.

shouldn't the registration option pop up first?

Good question. I’ve always used Netlify Identity with registration turned off and set up accounts manually in the Netlify dashboard, so I’m not actually sure if we need to do something more to show some registration UI. Maybe there’s some more information in the repo? https://github.com/netlify/netlify-identity-widget

Kuldas commented 1 year ago

Hi @delucis and thank you, just as you say. I used the fantastic guide in the documentation to get started. I discovered how what works and it was a joy to create something.πŸ’ͺ

Good question. I’ve always used Netlify Identity with registration turned off and set up accounts manually in the Netlify dashboard, so I’m not actually sure if we need to do something more to show some registration UI. Maybe there’s some more information in the repo? https://github.com/netlify/netlify-identity-widget

At the beginning I didn't notice manually adding the account in the Netlify dashboard πŸ˜… finally I did as you describe and it worked! Unfortunately, I have a new "problem". I'll try to describe it and maybe you can direct me to a solution πŸ˜„

For articles I have the following frontmatter:

---
layout: ../../layouts/MarkdownPostLayout.astro
title: My First Blog Post
pubDate: 25/11/2022
author: Astro Learner
description: This is the first post of my new Astro blog.
image:
  url: https://astro.build/assets/blog/astro-1-release-update/cover.jpeg
  alt: The Astro logo with the word One.
tags:
  - astro
  - blogging
  - learning in public
  - main
  - personal
  - My first tag
---

I have configured the following fields for Netlify CMS collections:

collections:  [
          {
            name: 'posts',
            label: 'Blog posts',
            folder: 'src/pages/posts',
            create: true,
            delete: true,
            fields: [
            {
              name: 'layout',
              widget: 'hidden',
              label: 'Layout',
              default: '../../layouts/MarkdownPostLayout.astro',
            },
            { name: 'title', widget: 'string', label: 'Post title' },
            {
              name: 'pubDate',
              widget: 'datetime',
              label: 'Publish date',
              format: 'DD/MM/YYYY',
              date_format: 'DD/MM/YYYY',
              time_format: false,
            },
            { name: 'author', widget: 'string', label: 'Author' },
            { name: 'description', widget: 'string', label: 'Description' },
            { 
              name: 'tags', 
              widget: 'list', 
              label: 'Tags', 
              summary: '{{fields.name}}',
              field: {
                label: 'Name',
                name: 'name',
                widget: 'string',
              }
            },
            { name: 'body', widget: 'markdown', label: 'Post body' },
            ],
          },
        ],

If I create a new article and don't add tags and an image, the build on Netlify fails. If I add tags but still no image, the build also fails. Only if I also insert an image (manually), the build finally creates and deploys. Below is a log with the error that occurs when trying to create the build.

2:59:22 AM:  generating static routes 
2:59:22 AM: β–Ά node_modules/astro-netlify-cms/admin-dashboard.astro
2:59:22 AM:   └─ /admin/index.html (+9ms)
2:59:22 AM: β–Ά src/pages/index.astro
2:59:22 AM:   └─ /index.html (+17ms)
2:59:22 AM: Ξ» src/pages/rss.xml.js
2:59:22 AM:   └─ /rss.xml (+4ms)
2:59:22 AM: β–Ά src/pages/about.astro
2:59:22 AM:   └─ /about/index.html (+10ms)
2:59:22 AM: β–Ά src/pages/posts/my-first-post-from-cms.md
2:59:22 AM:  error   Cannot read properties of undefined (reading 'url')
2:59:22 AM: TypeError: Cannot read properties of undefined (reading 'url')
2:59:22 AM: Creating deploy upload records
2:59:22 AM:     at default (file:///opt/build/repo/dist/entry.mjs?time=1669341562225:2041:243)
2:59:22 AM:     at renderChild (file:///opt/build/repo/dist/entry.mjs?time=1669341562225:920:24)
2:59:22 AM:     at async renderSlot (file:///opt/build/repo/dist/entry.mjs?time=1669341562225:950:22)
2:59:22 AM: ​
2:59:23 AM: Failed during stage 'building site': Build script returned non-zero exit code: 2 (https://ntl.fyi/exit-code-2)
2:59:22 AM: ────────────────────────────────────────────────────────────────
2:59:22 AM:   "build.command" failed                                        
2:59:22 AM: ────────────────────────────────────────────────────────────────
2:59:22 AM: ​
2:59:22 AM:   Error message
2:59:22 AM:   Command failed with exit code 1: npm run build (https://ntl.fyi/exit-code-1)
2:59:22 AM: ​
2:59:22 AM:   Error location
2:59:22 AM:   In Build command from Netlify app:
2:59:22 AM:   npm run build
2:59:22 AM: ​
2:59:22 AM:   Resolved config
2:59:22 AM:   build:
2:59:22 AM:     command: npm run build
2:59:22 AM:     commandOrigin: ui
2:59:22 AM:     publish: /opt/build/repo/dist
2:59:22 AM:     publishOrigin: ui
2:59:22 AM: Caching artifacts
2:59:22 AM: Started saving node modules
2:59:22 AM: Finished saving node modules
2:59:22 AM: Started saving build plugins
2:59:22 AM: Finished saving build plugins
2:59:22 AM: Started saving pip cache
2:59:22 AM: Finished saving pip cache
2:59:22 AM: Started saving emacs cask dependencies
2:59:22 AM: Finished saving emacs cask dependencies
2:59:22 AM: Started saving maven dependencies
2:59:22 AM: Finished saving maven dependencies
2:59:22 AM: Started saving boot dependencies
2:59:22 AM: Finished saving boot dependencies
2:59:22 AM: Started saving rust rustup cache
2:59:22 AM: Finished saving rust rustup cache
2:59:22 AM: Started saving go dependencies
2:59:22 AM: Finished saving go dependencies
2:59:22 AM: Build failed due to a user error: Build script returned non-zero exit code: 2
2:59:23 AM: Failing build: Failed to build site
2:59:23 AM: Finished processing build request in 36.069506292s
[Docs](https://docs.netlify.com/)
[Pricing](https://www.netlify.com/pricing/)
[Support](https://www.netlify.com/support)

I think the error is that the field is required, but if I assign required: false to the field, nothing changes.

Is there any other way to solve such a problem?