Skip to content

Commit dba7231

Browse files
Merge pull request #156 from oracle/authChanges
Removed use of Basic authentication for the sample app.
2 parents 597e88e + 276f5c9 commit dba7231

21 files changed

+1574
-75
lines changed

templates/ords-remix-jwt-sample/Database/Modules/concert_app.euser.v2.sql

Lines changed: 399 additions & 0 deletions
Large diffs are not rendered by default.

templates/ords-remix-jwt-sample/app/root.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import {
3030
} from './utils/auth.server';
3131
import NavBar from './components/navbar/NavBar';
3232
import {
33-
BASIC_SCHEMA_AUTH,
3433
CITIES_ENDPOINT,
3534
} from './routes/constants/index.server';
3635
import TooltipButton from './components/tooltips/TooltipButton';
@@ -42,12 +41,12 @@ export const loader = async ({ request }: LoaderFunctionArgs) => {
4241
const userProfile = await auth.isAuthenticated(request);
4342
const profile = userProfile?.profile || null;
4443
const USER_CREDENTIALS = userProfile === null
45-
? BASIC_SCHEMA_AUTH
44+
? null
4645
: `${userProfile.tokenType} ${userProfile.accessToken}`;
4746
const session = await getSession(request.headers.get('Cookie'));
4847
const error = session.get(auth.sessionErrorKey) as LoaderError;
4948

50-
const cities = await ORDSFetcher(CITIES_ENDPOINT, USER_CREDENTIALS);
49+
const cities = await ORDSFetcher(CITIES_ENDPOINT, USER_CREDENTIALS!);
5150
if (cities.items.length === 0) {
5251
const errorMessage = 'The cities endpoint has no elements. Review your database configuration and try again.';
5352
throw new Response(errorMessage, {

templates/ords-remix-jwt-sample/app/routes/artists.$id.tsx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import {
2222
ARTISTS_ENDPOINT,
2323
ARTIST_ENDPOINT,
2424
ARTIST_EVENT_ENDPOINT,
25-
BASIC_SCHEMA_AUTH,
2625
CITIES_ENDPOINT,
2726
LIKED_ARTIST_ENDPOINT,
2827
} from './constants/index.server';
@@ -87,26 +86,26 @@ export const loader = async ({
8786
const userProfile = await auth.isAuthenticated(request);
8887
const profile = userProfile?.profile || null;
8988
const USER_CREDENTIALS = userProfile === null
90-
? BASIC_SCHEMA_AUTH
89+
? null
9190
: `${userProfile.tokenType} ${userProfile.accessToken}`;
9291
const session = await getSession(request.headers.get('Cookie'));
9392
const error = session.get(auth.sessionErrorKey) as LoaderError;
9493
const { id: artistID } = params;
9594
let likedArtist = false;
96-
const artist = await ORDSFetcher(`${ARTIST_ENDPOINT}/${artistID}`, USER_CREDENTIALS) as ORDSResponse<Artist>;
95+
const artist = await ORDSFetcher(`${ARTIST_ENDPOINT}/${artistID}`, USER_CREDENTIALS!) as ORDSResponse<Artist>;
9796
if (artist.items.length === 0) {
9897
const errorMessage = 'The Artist you were looking for does not exist, might have been removed or had its id changed.';
9998
throw new Response(errorMessage, {
10099
status: 404,
101100
statusText: 'Not Found',
102101
} as ErrorResponse);
103102
}
104-
const artistEvents = await ORDSFetcher(`${ARTIST_EVENT_ENDPOINT}/${artistID}`, USER_CREDENTIALS);
105-
const similarArtists = await ORDSFetcher(ARTISTS_ENDPOINT, USER_CREDENTIALS);
106-
const cities = await ORDSFetcher(CITIES_ENDPOINT, USER_CREDENTIALS);
103+
const artistEvents = await ORDSFetcher(`${ARTIST_EVENT_ENDPOINT}/${artistID}`, USER_CREDENTIALS!);
104+
const similarArtists = await ORDSFetcher(ARTISTS_ENDPOINT, USER_CREDENTIALS!);
105+
const cities = await ORDSFetcher(CITIES_ENDPOINT, USER_CREDENTIALS!);
107106
if (profile) {
108107
const userID = profile.id;
109-
const userLikedArtist = await ORDSFetcher(`${LIKED_ARTIST_ENDPOINT}/${userID}/${artistID}`, USER_CREDENTIALS);
108+
const userLikedArtist = await ORDSFetcher(`${LIKED_ARTIST_ENDPOINT}/${userID}/${artistID}`, USER_CREDENTIALS!);
110109
likedArtist = userLikedArtist.likedartist === 1;
111110
}
112111
return json({

templates/ords-remix-jwt-sample/app/routes/concerts.$concertID.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import ConcertDetails from '../components/concerts/ConcertDetails';
2929
import {
3030
EVENT_ENDPOINT,
3131
LIKED_EVENT_ENDPOINT,
32-
BASIC_SCHEMA_AUTH,
3332
} from './constants/index.server';
3433
import { UserActions } from '../utils/UserActions';
3534
import ORDSFetcher from '../utils/ORDSFetcher';
@@ -93,12 +92,12 @@ export const loader = async ({
9392
const userProfile = await auth.isAuthenticated(request);
9493
const profile = userProfile?.profile || null;
9594
const USER_CREDENTIALS = userProfile === null
96-
? BASIC_SCHEMA_AUTH
95+
? null
9796
: `${userProfile.tokenType} ${userProfile.accessToken}`;
9897
const session = await getSession(request.headers.get('Cookie'));
9998
const error = session.get(auth.sessionErrorKey) as LoaderError;
10099
const { concertID } = params;
101-
const concert = await ORDSFetcher(`${EVENT_ENDPOINT}/${concertID}`, USER_CREDENTIALS) as ORDSResponse<Concert>;
100+
const concert = await ORDSFetcher(`${EVENT_ENDPOINT}/${concertID}`, USER_CREDENTIALS!) as ORDSResponse<Concert>;
102101
if (concert.items.length === 0) {
103102
const errorMessage = 'The Concert you were looking for does not exist, might have been removed or had its id changed.';
104103
throw new Response(errorMessage, {
@@ -109,7 +108,7 @@ export const loader = async ({
109108
let likedConcert = false;
110109
if (profile !== null) {
111110
const userID = profile.id;
112-
const userLikedConcert = await ORDSFetcher(`${LIKED_EVENT_ENDPOINT}/${userID}/${concertID}`, USER_CREDENTIALS);
111+
const userLikedConcert = await ORDSFetcher(`${LIKED_EVENT_ENDPOINT}/${userID}/${concertID}`, USER_CREDENTIALS!);
113112
likedConcert = userLikedConcert.likedevent === 1;
114113
}
115114

templates/ords-remix-jwt-sample/app/routes/home.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import {
2323
} from '../utils/auth.server';
2424
import {
2525
STATS_ENDPOINT,
26-
BASIC_SCHEMA_AUTH,
2726
EVENTS_ENDPOINT,
2827
ARTISTS_ENDPOINT,
2928
CONCERTS_BY_CITY_ENDPOINT,
@@ -43,17 +42,17 @@ import featureDescriptions from '../utils/ORDSFeaturesDescription';
4342
export const loader = async ({ request }: LoaderFunctionArgs) => {
4443
const userProfile = await auth.isAuthenticated(request);
4544
const USER_CREDENTIALS = userProfile === null
46-
? BASIC_SCHEMA_AUTH
45+
? null
4746
: `${userProfile.tokenType} ${userProfile.accessToken}`;
4847
const session = await getSession(request.headers.get('Cookie'));
4948
const error = session.get(auth.sessionErrorKey) as LoaderError;
5049
const { searchParams } = new URL(request.url);
5150
const hasCityName = searchParams.has('cityName');
5251
const cityName = searchParams.get('cityName');
5352
const eventsQuery = hasCityName ? `${CONCERTS_BY_CITY_ENDPOINT}/${cityName}` : EVENTS_ENDPOINT;
54-
const stats = await ORDSFetcher(STATS_ENDPOINT, USER_CREDENTIALS);
55-
const events = await ORDSFetcher(eventsQuery, USER_CREDENTIALS);
56-
const artists = await ORDSFetcher(ARTISTS_ENDPOINT, USER_CREDENTIALS);
53+
const stats = await ORDSFetcher(STATS_ENDPOINT, USER_CREDENTIALS!);
54+
const events = await ORDSFetcher(eventsQuery, USER_CREDENTIALS!);
55+
const artists = await ORDSFetcher(ARTISTS_ENDPOINT, USER_CREDENTIALS!);
5756
return json({
5857
error,
5958
stats,

templates/ords-remix-jwt-sample/app/routes/resources.artists.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import {
1515
} from '~/utils/auth.server';
1616
import {
1717
ARTISTS_ENDPOINT,
18-
BASIC_SCHEMA_AUTH,
1918
} from './constants/index.server';
2019
import ORDSFetcher from '../utils/ORDSFetcher';
2120

@@ -29,11 +28,11 @@ export const loader = async ({ request }: LoaderFunctionArgs) => {
2928
artistsURL.searchParams.append('limit', limit.toString());
3029
const userProfile = await auth.isAuthenticated(request);
3130
const USER_CREDENTIALS = userProfile === null
32-
? BASIC_SCHEMA_AUTH
31+
? null
3332
: `${userProfile.tokenType} ${userProfile.accessToken}`;
3433
const session = await getSession(request.headers.get('Cookie'));
3534
const error = session.get(auth.sessionErrorKey) as LoaderError;
36-
const artists = await ORDSFetcher(artistsURL, USER_CREDENTIALS);
35+
const artists = await ORDSFetcher(artistsURL, USER_CREDENTIALS!);
3736
return json({
3837
error,
3938
artists,

templates/ords-remix-jwt-sample/app/routes/resources.cities.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import {
1515
} from '~/utils/auth.server';
1616
import {
1717
CITIES_ENDPOINT,
18-
BASIC_SCHEMA_AUTH,
1918
} from './constants/index.server';
2019
import ORDSFetcher from '../utils/ORDSFetcher';
2120

@@ -29,11 +28,11 @@ export const loader = async ({ request }: LoaderFunctionArgs) => {
2928
citiesURL.searchParams.append('limit', limit.toString());
3029
const userProfile = await auth.isAuthenticated(request);
3130
const USER_CREDENTIALS = userProfile === null
32-
? BASIC_SCHEMA_AUTH
31+
? null
3332
: `${userProfile.tokenType} ${userProfile.accessToken}`;
3433
const session = await getSession(request.headers.get('Cookie'));
3534
const error = session.get(auth.sessionErrorKey) as LoaderError;
36-
const cities = await ORDSFetcher(citiesURL, USER_CREDENTIALS);
35+
const cities = await ORDSFetcher(citiesURL, USER_CREDENTIALS!);
3736
return json({
3837
error,
3938
cities,

templates/ords-remix-jwt-sample/app/routes/resources.concerts.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import {
1515
} from '~/utils/auth.server';
1616
import {
1717
EVENTS_ENDPOINT,
18-
BASIC_SCHEMA_AUTH,
1918
CONCERTS_BY_CITY_ENDPOINT,
2019
} from './constants/index.server';
2120
import ORDSFetcher from '../utils/ORDSFetcher';
@@ -33,11 +32,11 @@ export const loader = async ({ request }: LoaderFunctionArgs) => {
3332
eventsURL.searchParams.append('limit', limit.toString());
3433
const userProfile = await auth.isAuthenticated(request);
3534
const USER_CREDENTIALS = userProfile === null
36-
? BASIC_SCHEMA_AUTH
35+
? null
3736
: `${userProfile.tokenType} ${userProfile.accessToken}`;
3837
const session = await getSession(request.headers.get('Cookie'));
3938
const error = session.get(auth.sessionErrorKey) as LoaderError;
40-
const events = await ORDSFetcher(eventsURL, USER_CREDENTIALS);
39+
const events = await ORDSFetcher(eventsURL, USER_CREDENTIALS!);
4140
return json({
4241
error,
4342
events,

templates/ords-remix-jwt-sample/app/routes/resources.musicGenres.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import {
1414
getSession,
1515
} from '~/utils/auth.server';
1616
import {
17-
BASIC_SCHEMA_AUTH,
1817
MUSIC_GENRES_ENDPOINT,
1918
} from './constants/index.server';
2019
import ORDSFetcher from '../utils/ORDSFetcher';
@@ -31,13 +30,13 @@ export const loader = async ({ request }: LoaderFunctionArgs) => {
3130
musicGenresURL.searchParams.append('limit', limit.toString());
3231
const userProfile = await auth.isAuthenticated(request);
3332
const USER_CREDENTIALS = userProfile === null
34-
? BASIC_SCHEMA_AUTH
33+
? null
3534
: `${userProfile.tokenType} ${userProfile.accessToken}`;
3635
const session = await getSession(request.headers.get('Cookie'));
3736
const error = session.get(auth.sessionErrorKey) as LoaderError;
3837
const musicGenres = await ORDSFetcher(
3938
musicGenresURL,
40-
USER_CREDENTIALS,
39+
USER_CREDENTIALS!,
4140
) as ORDSResponse<MusicGenre>;
4241
return json({
4342
error,

templates/ords-remix-jwt-sample/app/routes/resources.venues.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import {
1515
} from '~/utils/auth.server';
1616
import {
1717
VENUES_ENDPOINT,
18-
BASIC_SCHEMA_AUTH,
1918
} from './constants/index.server';
2019
import ORDSFetcher from '../utils/ORDSFetcher';
2120
import ORDSResponse from '../models/ORDSResponse';
@@ -31,11 +30,11 @@ export const loader = async ({ request }: LoaderFunctionArgs) => {
3130
venuesURL.searchParams.append('limit', limit.toString());
3231
const userProfile = await auth.isAuthenticated(request);
3332
const USER_CREDENTIALS = userProfile === null
34-
? BASIC_SCHEMA_AUTH
33+
? null
3534
: `${userProfile.tokenType} ${userProfile.accessToken}`;
3635
const session = await getSession(request.headers.get('Cookie'));
3736
const error = session.get(auth.sessionErrorKey) as LoaderError;
38-
const venues = await ORDSFetcher(venuesURL, USER_CREDENTIALS) as ORDSResponse<Venue>;
37+
const venues = await ORDSFetcher(venuesURL, USER_CREDENTIALS!) as ORDSResponse<Venue>;
3938
return json({
4039
error,
4140
venues,

templates/ords-remix-jwt-sample/app/routes/search.$searchKind.$searchParam.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import type {
1111
import { json } from '@remix-run/node';
1212
import { auth } from '~/utils/auth.server';
1313
import {
14-
BASIC_SCHEMA_AUTH,
1514
ARTISTS_ENDPOINT,
1615
VENUES_ENDPOINT,
1716
EVENTS_BY_NAME_ENDPOINT,
@@ -30,14 +29,14 @@ export const loader = async ({
3029
const { searchKind, searchParam } = params;
3130
const userProfile = await auth.isAuthenticated(request);
3231
const USER_CREDENTIALS = userProfile === null
33-
? BASIC_SCHEMA_AUTH
32+
? null
3433
: `${userProfile.tokenType} ${userProfile.accessToken}`;
3534
// eslint-disable-next-line no-magic-numbers
3635
const FOLLOWERS = [69420, 99876, 45632, 32496, 98765, 12776, 100000, 88999, 99999];
3736

3837
switch (searchKind) {
3938
case 'Artists': {
40-
const artists = await ORDSFetcher(`${ARTISTS_ENDPOINT}/${searchParam}`, USER_CREDENTIALS);
39+
const artists = await ORDSFetcher(`${ARTISTS_ENDPOINT}/${searchParam}`, USER_CREDENTIALS!);
4140
const SearchResult = artists.items.map((artist: Artist, index : number) => ({
4241
id: artist.artist_id,
4342
kind: 'artists',
@@ -50,7 +49,7 @@ export const loader = async ({
5049
});
5150
}
5251
case 'Events': {
53-
const events = await ORDSFetcher(`${EVENTS_BY_NAME_ENDPOINT}/${searchParam}`, USER_CREDENTIALS);
52+
const events = await ORDSFetcher(`${EVENTS_BY_NAME_ENDPOINT}/${searchParam}`, USER_CREDENTIALS!);
5453
const SearchResult = events.items.map((event: Concert) => ({
5554
id: event.event_id,
5655
kind: 'concerts',
@@ -63,7 +62,7 @@ export const loader = async ({
6362
});
6463
}
6564
case 'Venues': {
66-
const venues = await ORDSFetcher(`${VENUES_ENDPOINT}/${searchParam}`, USER_CREDENTIALS);
65+
const venues = await ORDSFetcher(`${VENUES_ENDPOINT}/${searchParam}`, USER_CREDENTIALS!);
6766
const SearchResult = venues.items.map((venue: Venue) => ({
6867
id: venue.venue_id,
6968
kind: 'venues',
@@ -79,7 +78,7 @@ export const loader = async ({
7978
headers: {
8079
'Content-Type': 'application/json',
8180
Accept: 'application/json',
82-
Authorization: USER_CREDENTIALS,
81+
Authorization: USER_CREDENTIALS!,
8382
},
8483
});
8584
const artists = await getArtist.json();

templates/ords-remix-jwt-sample/app/routes/search.artists.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import {
2020
auth, getSession,
2121
} from '../utils/auth.server';
2222
import {
23-
BASIC_SCHEMA_AUTH,
2423
MUSIC_GENRES_ENDPOINT,
2524
AUTO_REST_SEARCH_ARTISTS_ENDPOINT,
2625
} from './constants/index.server';
@@ -34,7 +33,7 @@ import DiscoverArtists from '../components/search/DiscoverArtists';
3433
export const loader = async ({ request }: LoaderFunctionArgs) => {
3534
const userProfile = await auth.isAuthenticated(request);
3635
const USER_CREDENTIALS = userProfile === null
37-
? BASIC_SCHEMA_AUTH
36+
? null
3837
: `${userProfile.tokenType} ${userProfile.accessToken}`;
3938
const session = await getSession(request.headers.get('Cookie'));
4039
const error = session.get(auth.sessionErrorKey) as LoaderError;
@@ -51,11 +50,11 @@ export const loader = async ({ request }: LoaderFunctionArgs) => {
5150
searchURL.searchParams.append('offset', offset.toString());
5251
const searchResult = await ORDSFetcher(
5352
searchURL,
54-
USER_CREDENTIALS,
53+
USER_CREDENTIALS!,
5554
) as ORDSResponse<ArtistResult>;
5655
const musicGenres = await ORDSFetcher(
5756
MUSIC_GENRES_ENDPOINT,
58-
USER_CREDENTIALS,
57+
USER_CREDENTIALS!,
5958
) as ORDSResponse<MusicGenre>;
6059

6160
return json({

templates/ords-remix-jwt-sample/app/routes/search.concerts.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import {
2020
auth, getSession,
2121
} from '../utils/auth.server';
2222
import {
23-
BASIC_SCHEMA_AUTH,
2423
AUTO_REST_SEARCH_ENDPOINT,
2524
CITIES_ENDPOINT,
2625
ARTISTS_ENDPOINT,
@@ -38,7 +37,7 @@ import Artist from '../models/Artist';
3837
export const loader = async ({ request }: LoaderFunctionArgs) => {
3938
const userProfile = await auth.isAuthenticated(request);
4039
const USER_CREDENTIALS = userProfile === null
41-
? BASIC_SCHEMA_AUTH
40+
? null
4241
: `${userProfile.tokenType} ${userProfile.accessToken}`;
4342
const session = await getSession(request.headers.get('Cookie'));
4443
const error = session.get(auth.sessionErrorKey) as LoaderError;
@@ -55,11 +54,11 @@ export const loader = async ({ request }: LoaderFunctionArgs) => {
5554
searchURL.searchParams.append('offset', offset.toString());
5655
const searchResult = await ORDSFetcher(
5756
searchURL,
58-
USER_CREDENTIALS,
57+
USER_CREDENTIALS!,
5958
) as ORDSResponse<SearchResult>;
60-
const cities = await ORDSFetcher(CITIES_ENDPOINT, USER_CREDENTIALS) as ORDSResponse<City>;
61-
const venues = await ORDSFetcher(VENUES_ENDPOINT, USER_CREDENTIALS) as ORDSResponse<Venue>;
62-
const artists = await ORDSFetcher(ARTISTS_ENDPOINT, USER_CREDENTIALS) as ORDSResponse<Artist>;
59+
const cities = await ORDSFetcher(CITIES_ENDPOINT, USER_CREDENTIALS!) as ORDSResponse<City>;
60+
const venues = await ORDSFetcher(VENUES_ENDPOINT, USER_CREDENTIALS!) as ORDSResponse<Venue>;
61+
const artists = await ORDSFetcher(ARTISTS_ENDPOINT, USER_CREDENTIALS!) as ORDSResponse<Artist>;
6362

6463
return json({
6564
error,

templates/ords-remix-jwt-sample/app/routes/search.venues.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import {
2020
auth, getSession,
2121
} from '../utils/auth.server';
2222
import {
23-
BASIC_SCHEMA_AUTH,
2423
AUTO_REST_SEARCH_VENUES_ENDPOINT,
2524
CITIES_ENDPOINT,
2625
} from './constants/index.server';
@@ -34,7 +33,7 @@ import ORDSResponse from '../models/ORDSResponse';
3433
export const loader = async ({ request }: LoaderFunctionArgs) => {
3534
const userProfile = await auth.isAuthenticated(request);
3635
const USER_CREDENTIALS = userProfile === null
37-
? BASIC_SCHEMA_AUTH
36+
? null
3837
: `${userProfile.tokenType} ${userProfile.accessToken}`;
3938
const session = await getSession(request.headers.get('Cookie'));
4039
const error = session.get(auth.sessionErrorKey) as LoaderError;
@@ -51,9 +50,9 @@ export const loader = async ({ request }: LoaderFunctionArgs) => {
5150
searchURL.searchParams.append('offset', offset.toString());
5251
const searchResult = await ORDSFetcher(
5352
searchURL,
54-
USER_CREDENTIALS,
53+
USER_CREDENTIALS!,
5554
) as ORDSResponse<VenueResult>;
56-
const cities = await ORDSFetcher(CITIES_ENDPOINT, USER_CREDENTIALS) as ORDSResponse<City>;
55+
const cities = await ORDSFetcher(CITIES_ENDPOINT, USER_CREDENTIALS!) as ORDSResponse<City>;
5756

5857
return json({
5958
error,

0 commit comments

Comments
 (0)