generated from taylorbryant/gatsby-starter-tailwind
-
-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin' into map-areaid-share
- Loading branch information
Showing
22 changed files
with
229 additions
and
1,448 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { NextRequest, NextResponse } from 'next/server' | ||
import * as Auth0 from 'auth0' | ||
import { auth0Client, isNullOrEmpty } from '@/js/auth/mobile' | ||
import { withMobileAuth } from '@/js/auth/withMobileAuth' | ||
|
||
/** | ||
* Mobile login handler | ||
*/ | ||
async function postHandler (request: NextRequest): Promise<NextResponse> { | ||
let username: string, password: string | ||
try { | ||
const data = await request.json() | ||
username = data.username | ||
password = data.password | ||
|
||
if (isNullOrEmpty(username) || isNullOrEmpty(password)) { | ||
console.error('Empty username/password!') | ||
throw new Error('Invalid payload') | ||
} | ||
} catch (error) { | ||
return NextResponse.json({ error: 'Unexpected error', status: 400 }) | ||
} | ||
|
||
let response: Auth0.JSONApiResponse<Auth0.TokenSet> | undefined | ||
try { | ||
response = await auth0Client.oauth.passwordGrant({ | ||
username, | ||
password, | ||
scope: 'openid profile email offline_access', | ||
audience: 'https://api.openbeta.io', | ||
realm: 'Username-Password-Authentication' | ||
}) | ||
|
||
return NextResponse.json({ data: response.data }) | ||
} catch (error) { | ||
console.error('#### Auth0 error ####', error) | ||
return NextResponse.json({ error: 'Unexpected auth error', status: 403 }) | ||
} | ||
} | ||
|
||
export const POST = withMobileAuth(postHandler) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { NextRequest, NextResponse } from 'next/server' | ||
import * as Auth0 from 'auth0' | ||
import { auth0Client, isNullOrEmpty } from '@/js/auth/mobile' | ||
import { withMobileAuth } from '@/js/auth/withMobileAuth' | ||
|
||
/** | ||
* Mobile refresh token handler | ||
*/ | ||
async function postHandler (request: NextRequest): Promise<any> { | ||
let refreshToken: string | ||
try { | ||
const data = await request.json() | ||
refreshToken = data.refreshToken | ||
|
||
if (isNullOrEmpty(refreshToken)) { | ||
console.error('Empty refreshToken!') | ||
throw new Error('Invalid payload') | ||
} | ||
} catch (error) { | ||
return NextResponse.json({ error: 'Unexpected error', status: 400 }) | ||
} | ||
|
||
let response: Auth0.JSONApiResponse<Auth0.TokenSet> | undefined | ||
try { | ||
response = await auth0Client.oauth.refreshTokenGrant({ | ||
refresh_token: refreshToken, | ||
audience: 'https://api.openbeta.io' | ||
}) | ||
|
||
return NextResponse.json({ data: response.data }) | ||
} catch (error) { | ||
console.error('#### Auth0 error ####', error) | ||
return NextResponse.json({ error: 'Unexpected auth error', status: 403 }) | ||
} | ||
} | ||
|
||
export const POST = withMobileAuth(postHandler) |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.