Skip to content

Commit

Permalink
Handling missing name
Browse files Browse the repository at this point in the history
  • Loading branch information
leighhalliday committed Sep 10, 2019
1 parent 4f52dbf commit c5233fd
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions pages/api/auth/connect.ts
Expand Up @@ -39,9 +39,11 @@ async function getUser(accessToken) {
}

async function insertUser(data: GithubData): Promise<User | null> {
const username: string = data.login.toLowerCase();

await db("users").insert({
name: data.name,
username: data.login.toLowerCase(),
name: data.name || username,
username: username,
github_id: data.id,
website_url: data.blog,
github_url: data.html_url,
Expand All @@ -52,10 +54,12 @@ async function insertUser(data: GithubData): Promise<User | null> {
}

async function updateUser(data: GithubData): Promise<User> {
const username: string = data.login.toLowerCase();

await db("users")
.where({ github_id: data.id })
.update({
name: data.name,
name: data.name || username,
website_url: data.blog,
github_url: data.html_url,
updated_at: new Date().toISOString()
Expand Down

1 comment on commit c5233fd

@vercel
Copy link

@vercel vercel bot commented on c5233fd Sep 10, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.