Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

Save login number to constituent table

Abierto
#705 0 comentarios 0 reacciones 2 asignados Ver en GitHub

@EmaleeSoto ya está trabajando en esto.

Desde el 16/11/2023.

Evaluación

Este issue todavía no se ha evaluado.

Descripción

Goal: collect number from Auth0 login process and save into constituent table so we have the ability to send notifications later on

Background info

Constituent table lives within: amplify/server/db/migrations/20220413154827_rename-volunteers-table-to-constituents.js

Image

Data types:

  • name is a string
  • Street address, City, and State are strings
  • Zipcode is a string
  • Letters sent holds an array of ids of letter that was successfully posted with Lob (payment and address verification went through)
  • User agreement is a boolean that they abide by the platforms outlined = community safety and protection guidelines
  • Updates is sending campaign_id so that we can send to advocacy groups so they can follow up and by our user education team

Directions

To save the user's phone number from Auth0 Universal Login to the constituent table, you can modify the up function of the migration file that creates the constituent table. Here are the steps you can follow:

  • 1. Add a new column to the constituent table to store the phone number:
exports.up = function(knex) {
  return knex.schema.createTable('constituent', (table) => {
    table.increments('id').primary()
    table.string('name').notNullable()
    table.string('email').notNullable().unique()
    table.string('phone_number') // Add this line
    table.timestamps(true, true)
  })
}
  • 2. Modify the down function of the migration file to drop the phone_number column:
exports.down = function(knex) {
  return knex.schema.dropTable('constituent')
}
  • 3. In your Express app, modify the /callback route to save the user's phone number to the constituent table:
router.get('/callback', passport.authenticate('auth0', {
  failureRedirect: '/login'
}), async (req, res) => {
  const { phone_number } = req.user._json // Get the phone number from the user object
  const { name, email } = req.user // Get the name and email from the user object

  try {
    // Check if the user already exists in the constituent table
    const existingConstituent = await knex('constituent').where({ email }).first()

    if (existingConstituent) {
      // Update the existing constituent with the phone number
      await knex('constituent').where({ email }).update({ phone_number })
    } else {
      // Create a new constituent with the name, email, and phone number
      await knex('constituent').insert({ name, email, phone_number })
    }

    res.redirect('/')
  } catch (error) {
    console.error(error)
    res.status(500).send('Internal server error')
  }
})

This code gets the phone number from the req.user._json object, which is provided by Passport when the user is authenticated. It then checks if the user already exists in the constituent table based on their email address. If the user exists, it updates their phone number. If the user does not exist, it creates a new constituent with the name, email, and phone number.

  • Note that you will need to import the knex object and the passport middleware in your Express app for this code to work.
Lenguaje dominante
JavaScript
Estrellas
120
Forks
101
Métricas de merge de PR
Sin PR fusionados en 30 d

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de OpenSourceFellows/amplify

Todos los issues de OpenSourceFellows/amplify

Issues similares

Más issues de JavaScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.