-
-
Notifications
You must be signed in to change notification settings - Fork 129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add mobile login handler #1207
Changes from all commits
e46f1cc
d032de1
5bf7103
993bd1b
4d102d7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
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' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should this be generalized to whatever the current environment is? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The settings are identical for both dev/stg and prod. |
||
}) | ||
|
||
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) |
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' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same comment as above |
||
}) | ||
|
||
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.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Jumping from v2 -> v4 broke a lot of user management code